将str时间转换为java中的kml timeStamp

时间:2015-05-14 07:51:49

标签: java timestamp kml

我构建了一个kml文件,并且有一行时间戳:

<gx:TimeStamp>
          <when>2002-07-09T19:00:00-08:00</when>
        </gx:TimeStamp>

我需要转换时间,如:“1430477311”到“2002-07-09T19:00:00-08:00”格式

怎么样? (java code) tnx很多

2 个答案:

答案 0 :(得分:2)

您想要从时间格式转换为XML日期格式(ISO-8601) -

long timeStamp = 1430477311L;
java.util.Date yourDate = new java.util.Date(timeStamp*1000); //ms
SimpleDateFormat yyyyMMddTHHmmssSDF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
String date = yyyyMMddTHHmmssSDF.format(yourDate);

Simple Date Format reference

答案 1 :(得分:1)

只需将时间戳传递给Date类型:

Timestamp stamp = new Timestamp(inputTimestamp);
Date date = new Date(stamp.getTime());
//change the to the format that you need
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
String timeStr = df.format(date);