给出一个字符串下面,我要转换:

1月2008年06:43:00+0100

年/月/日HH:MM:SSAM

使用script什么是最好的方式做到这一点?

有帮助吗?

解决方案

我没有Jython的方便,但是我希望是这样工作的:

import java
sdf = java.text.SimpleDateFormat

fmt_in = sdf('d MMM yyyy HH:mm:ss Z')
fmt_out = sdf('MM/dd/yyyy HH:mm:ssaa')

fmt_out.format(fmt_in.parse(time_str))

其他提示

Script 2.5b0(β)有一个执行情况 时间模块 这包括

strptime(string[, format]).

分析一串代表时根据格式。返回值是struct_time为返回的gmtime()或localtime().

(strptime 在Jython2.2.1).

蟒蛇版本的转换格式将看起来象(不确定的区域成分):

import time
mytime = time.strptime("1 Dec 2008 06:43:00 +0100", "%d %b %Y %H:%M:%S %Z")
new_time_string = time.strftime("%m/%d/%Y %I:%M:%S%p", mytime)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top