SHARE
TWEET

Output RFC 3339 Timestamp in Java

code_junkie Nov 12th, 2011 907 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top