Win a copy of Head First Android this week in the Android 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

How to display date in Daylight Savings

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to transfer the date in 'yyyymmdd hh.mm.ss' 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;

tempDate.append(timeStamp);
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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic