Win a copy of Production-Ready Serverless (Operational Best Practices) this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

How to display date in Daylight Savings  RSS feed

Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to transfer the date in 'yyyymmdd' format to "Tue Jun 12 13:54:42 EDT 2007" format.

I have the following code:
private String formatTimeStamp(String timeStamp) {
StringBuffer tempDate = new StringBuffer();
int year;
int day;
int month;
int hour;
int minute;
int second;

year = Integer.parseInt(tempDate.substring(0, 4));
month = Integer.parseInt(tempDate.substring(4, 6));
day = Integer.parseInt(tempDate.substring(6, 8));
hour = Integer.parseInt(tempDate.substring(9, 11));
minute = Integer.parseInt(tempDate.substring(12, 14));
second = Integer.parseInt(tempDate.substring(15, 17));

return (new Date((year-1900), (month-1), day, hour, minute, second).toString());

However, this gives date as: Tue Jun 12 13:54:42 EST 2007

Is there something I should initialize or follow different way to code?
Thanks in advance.
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you should be using the SimpleDateFormat class or any of the other Date Formatters you already have with Java. Take a look at SimpleDateFormat and you will get a better solution.
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, note that the Date constructor which you've used has been deprecated. The API suggests a way to use a Calendar to do this, but personally I would usually use a DateFormat. Something like this:

However I suspect that the real problem here is in how your computer's time zone has been set. If you're on Windows, go to Control Panel -> Date/Time -> Time Zone, select "Eastern Time", and select "Automatically adjust clock for daylight savings". If that doesn't work, please describe what operating system you're using, and what the time zone is currently set to.
You get good luck from rubbing the belly of a tiny ad:
global solutions you can do in your home or backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!