Topic
  • 1 reply
  • Latest Post - ‏2012-04-04T10:18:33Z by SystemAdmin
Y9KH_venkat_rao
Y9KH_venkat_rao
10 Posts

Pinned topic jdk1.6 +(GMT-06:00) Central Time (US & Canada) +2012-03-11 2-3 hours issue

‏2012-04-04T05:27:58Z |
Hi Team,

I am struggeling the issue with jdk1.6+(GMT-06:00) Central Time (US & Canada) for the date and time of 2012-03-11 2:00-3:00 .

Please run below code for we get the wrong result for the time of 2:00-3:00 hours.

Can some one please give me where i am doing wrong or give the any other solution for fixing the issue in jdk1.6 .

package com.test;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
*
• @author Brenden
*/
public class TimeStampTest
{

static String testStrings[] = { "2012-03-11 01:45:00",
"2012-03-11 02:00:00", "2012-03-11 02:15:00",
"2012-03-11 02:30:00", "2012-03-11 02:45:00",
"2012-03-11 03:00:00", };

public static void main(String[] args) throws Exception {
for (String test : testStrings) {
System.out.println("Original: " + test);
System.out.println("Timestamp: "
+ toSqlTimestamp(test, "yyyy-MM-dd HH:mm:ss"));
}
}

public static Timestamp toSqlTimestamp(String date, String fmt)
throws ParseException, Exception {
Timestamp res = null;
try {
SimpleDateFormatf = new SimpleDateFormat(fmt);
res = new Timestamp(f.parse(date).getTime());
} catch (ParseException pexc) {
throw pexc;
} catch (Exception exc) {
throw exc;
}
return res;
}
}

Rgards,
Venkat
Updated on 2012-04-04T10:18:33Z at 2012-04-04T10:18:33Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    37422 Posts

    Re: jdk1.6 +(GMT-06:00) Central Time (US & Canada) +2012-03-11 2-3 hours issue

    ‏2012-04-04T10:18:33Z  
    Didn't someone explain in your other thread for this issue that 3/11 between 2-3 is an imaginary time since there was a DST leap?