Jython 日期到字符串的转换
Jython Date to String conversion
如何在 jython 中将日期对象 2017-09-09 打印为字符串 '2017-09-09'?
我需要在 Jython 中将值 [ 2017-09-09 + string ] 设置为字符串。
我尝试了以下方法:
- str(2017-09-09)
- 打印 ("'" + 2017-09-09 + "'")
但它给出了错误。
示例:
package com.myexample;
public class SomeClassInJAVA(){
public static Date getDate(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date d = sdf.parse("1972-09-09");
return d;
}
}
//Jython 脚本
from com.myexample import SomeClassInJAVA
d = SomeClassInJAVA.getDate()
print d //prints d as 1972-09-09
print str(d) //returns error
print "'" + d + "'"
假设我在 jython
中将接收到的日期转换回 Java 字符串
s = SimpleDateFormat("yyyy-MM-dd").format(d)
print s // prints s as 1972-09-09
如何将其转换为“1972-09-09”
有人可以帮忙吗?提前致谢
根据评论,您的转换需要发生在之后您获得 JythonDate,而不是之前:
myStr = "some string" + str(jythonDate);
如何在 jython 中将日期对象 2017-09-09 打印为字符串 '2017-09-09'?
我需要在 Jython 中将值 [ 2017-09-09 + string ] 设置为字符串。 我尝试了以下方法:
- str(2017-09-09)
- 打印 ("'" + 2017-09-09 + "'")
但它给出了错误。 示例:
package com.myexample;
public class SomeClassInJAVA(){
public static Date getDate(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date d = sdf.parse("1972-09-09");
return d;
}
}
//Jython 脚本
from com.myexample import SomeClassInJAVA
d = SomeClassInJAVA.getDate()
print d //prints d as 1972-09-09
print str(d) //returns error
print "'" + d + "'"
假设我在 jython
中将接收到的日期转换回 Java 字符串s = SimpleDateFormat("yyyy-MM-dd").format(d)
print s // prints s as 1972-09-09
如何将其转换为“1972-09-09”
有人可以帮忙吗?提前致谢
根据评论,您的转换需要发生在之后您获得 JythonDate,而不是之前:
myStr = "some string" + str(jythonDate);