Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python jython日期转换_Python_Jython_Date Conversion - Fatal编程技术网

Python jython日期转换

Python jython日期转换,python,jython,date-conversion,Python,Jython,Date Conversion,给定如下字符串,我需要转换: 2008年12月1日06:43:00+0100 到 年月日HH:MM:SSAM 使用jython做这件事的最佳方法是什么?我手头没有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.pa

给定如下字符串,我需要转换:

2008年12月1日06:43:00+0100

年月日HH:MM:SSAM


使用jython做这件事的最佳方法是什么?

我手头没有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))
2.5b0(beta版)具有以下功能的实现:

strptime(字符串[,格式])

根据格式解析表示时间的字符串。返回值是gmtime()或localtime()返回的struct_time

strtime
在Jython2.2.1中缺失)

转换格式的python版本如下所示(不确定区域组件):


jython 2.2.1不支持time.strtime。从jython 2.5.2开始,遗憾的是,内置strtime没有检测到大多数错误,而是返回假时间:。另一种选择是,您可以尝试使用strptime的纯Python实现:当time.strptime()不行时,您可以回到Java端-
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)