JavaServer Pages (JSP) and JSTL - Issues related TimeZOnes and Time

1) In my MYSQL database there is column of type DATETIME name is "ts"

assume my database is located in America/Any other part of the world , Then the local time of america will be stored in MYSQL ts (DATETIME) column.

2) Now i want to convert that local time in AMerica into TImezone of india/calcutta

For that i am using the following code .

// 1) Define a Calendar with correct time zone

// 2) Intialize the Calendar with the proper number of milliseconds

//rs is result set

ts1= rs.getTimestamp("ts")

Calendar local = Calendar.getInstance(TimeZone.getTimeZone("Asia/Calcutta"));

//ts1,getTime will give time in Milliseconds

local.setTimeInMillis(ts1.getTime());

int dayofthemonth = local.get(Calendar.DAY_OF_MONTH);

int month = local.get(Calendar.MONTH);

int year = local.get(Calendar.YEAR);

month = month + 1;

Is the above procedure is Correct?

My Server is located in America and iam rendering the jsp webpages in India I could not able to get the proper time.

Is there any flaw in the above code?

Thanks

Rama

[1178 byte] By [Ramaaa] at [2007-11-26 23:10:07]
# 1

Is there any flaw in the above code?

It doesn't do what you want. I would consider it a flaw if my code didn't do what I wanted. Wouldn't you?

Anyway, here's what I think you should do:

Timestamp ts1= rs.getTimestamp("ts") ;

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

sdf.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta"));

String theAnswer = sdf.format(ts1);

DrClapa at 2007-7-10 14:05:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks DrClap I will check it out.
Ramaaa at 2007-7-10 14:05:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...