• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Formatting date object using TimeZone

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I want to format date in following format:



I am using following code:


above code produces date in following form


i.e. without colon for time zone.

my application requires time zone with the colon (+05:30), whereas above code produces
timezone without colon.

Can some one help me what modifications can I perform for timezone with colon?

Thanks.
Nikesh
 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking at the javadocs for SimpleDateFormat, I'm not sure if it's possible. 'Z' and 'z' are close to what you need, but not perfect. You might have to do some manual string manipulation to add the colon.
 
Nikes Shah
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Michael,

It seems manually i will have to add colon for time zone.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The format you're asking for looks like ISO 8601, which is what's used in XML files as the standard format for timestamps.

Unfortunately, SimpleDateFormat does not have proper support for this, and it's indeed not possible to use SimpleDateFormat to produce a string in the form that you want. One solution is to add the colon by hand.

You could have a look at Joda Time, a popular open source library for dealing with dates and times in Java, which does have proper support for ISO 8601.
 
Nikes Shah
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I am dealing with web services which requires timezone in ISO 8601.

Thanks for the Joda Time library link.

 
Did you just should on me? You should read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic