Output RFC 3339 Timestamp in Java -
i want output timestamp pst offset (e.g., 2008-11-13t13:23:30-08:00). java.util.simpledateformat
not seem output timezone offsets in hour:minute format, excludes colon. there simple way timestamp in java?
// want 2008-11-13t12:23:30-08:00 string timestamp = new simpledateformat("yyyy-mm-dd't'h:m:ssz").format(new date()); system.out.println(timestamp); // prints "2008-11-13t12:23:30-0800" see difference?
also, simpledateformat
cannot parse example above. throws parseexception
.
// throws parseexception new simpledateformat("yyyy-mm-dd't'h:m:ssz").parse("2008-11-13t13:23:30-08:00")
starting in java 7, there's x
pattern string iso8601 time zone. strings in format describe, use xxx
. see documentation.
sample:
system.out.println(new simpledateformat("yyyy-mm-dd't'hh:mm:ssxxx") .format(new date()));
result:
2014-03-31t14:11:29+02:00
Comments
Post a Comment