code_junkie

Output RFC 3339 Timestamp in Java

Nov 12th, 2011
1,307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. // I want 2008-11-13T12:23:30-08:00
  2. String timestamp = new SimpleDateFormat("yyyy-MM-dd'T'h:m:ssZ").format(new Date());
  3. System.out.println(timestamp);
  4. // prints "2008-11-13T12:23:30-0800" See the difference?
  5.  
  6. // Throws a ParseException
  7. new SimpleDateFormat("yyyy-MM-dd'T'h:m:ssZ").parse("2008-11-13T13:23:30-08:00")
  8.  
  9. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'h:m:ss.SZ");
Add Comment
Please, Sign In to add comment