Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Output a date with timezone, in W3C datetime format?

 
Jimi Svedenholm
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Unless I'm blind, I can't find an easy way to output a date in W3C datetime format, with timezon.

What I want is what W3C describes as YYYY-MM-DDThh:mm:ssTZD.
For example: 1997-07-16T19:20:30+01:00

http://www.w3.org/TR/NOTE-datetime

I looked at the SimpleDateFormat, but I can't find any way to get the timezone part with the colon between hour and minute. When I use the "Z" pattern it will not include the colon, and when I use the "z" pattern it prints "CET".

Any suggestions? I would really prefer not having to do string manipulations. And this should be doable using only standard java classes. Or?

Regards
/Jimi
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15438
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've come across this problem also sometime. Unfortunately, there does not seem to be a way to make SimpleDateFormat format the timezone with the colon, so you'll have to do manually...:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic