java - java中时间戳字符串转时间戳

标签 java date timestamp

我有以下字符串“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/

相关文章:

java - Spring中创建的Proxy的Proxy

wordpress - 如何修改wordpress列表评论中的日期格式

date - 从 Apps 脚本 V8 和旧版中的 google 工作表检索到不同的日期值

c++ - 在 C++ 中可靠地比较不同机器的时间戳

regex - 创建表期间解析 Hive 中的时间戳

Javascript日期到UTC时间戳

java - Java 中初始化的奇怪行为

java - 以异步方式实现 Envers 审计的可能性

java - RabbitMQ basicPublish 不将消息插入队列

R时间序列数据,每天只有工作日