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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -