简体   繁体   English

将字符串时间戳与偏移量转换为Java日期

[英]Convert String timestamp with offset to Java date

I need to convert this timestamp string to a Java Date object 我需要将此时间戳字符串转换为Java Date对象

2014-04-03T14:02:57.182+0200

How do I do this? 我该怎么做呢? How do I handle the time offset included in the timestamp 如何处理时间戳中包含的时间偏移量

You can use this code: 您可以使用此代码:

String strdate = "2014-04-03T14:02:57.182+0200";
Date date = new SimpleDateFormat("yyyy-mm-dd'T'HH:mm:ss.SSSZ").parse(strdate);
System.out.println(date);

Thread-safe alternative from apache commons lang3. 来自apache commons lang3的线程安全替代方案。 First: 第一:

import org.apache.commons.lang3.time.FastDateFormat;

then: 然后:

String strdate = "2014-04-03T14:02:57.182+0200";
String dateFormatPattern = "yyyy-mm-dd'T'HH:mm:ss.SSSZ";
Date date = FastDateFormat.getInstance(dateFormatPattern).parse(strdate);
System.out.println(date);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM