我有以下字符串“2015-04-02 11:52:00+02”,我需要在 Java 中将其解析为时间戳。 我尝试了各种格式,包括
SimpleDateFormat mdyFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss+Z");
但似乎没有任何效果 - 我不断收到 ParseException
有人可以帮忙吗?
我需要类似的东西:
SimpleDateFormat mdyFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss+Z");
Timestamp t = new Timestamp(mdyFormat.parse("2015-04-02 11:52:00+02").getTime());
最佳答案
试试这个
String str="2009-12-31 23:59:59 +0100";
/\
||
Provide Space while providing timeZone
SimpleDateFormat mdyFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
System.out.println(mdyFormat.parse(str));
输出
Fri Jan 01 04:29:59 IST 2010
关于java - java中时间戳字符串转时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29415155/