• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Server in canada but need Indian date and time

 
Prady Kural
Greenhorn
Posts: 14
Java Oracle Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
every one
I have a web-application to be deployed on tomcat in Canada,
My web application uses real-time monitoring of database, that monitoring should be strictly according to Indian date and time.
I have used following code.
how to modify/add something to it so that it work fine as per my requirements.
...................
.....................
..............
// Create an instance of SimpleDateFormat used for formatting
// the string representation of date (day/month/year)
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
// Get the date today using Calendar object.
Date today = Calendar.getInstance().getTime();
// Using DateFormat format method we can create a string
// representation of a date with the defined format.
String todaydate = df.format(today);
// Print what date is today!
System.out.println("Report Date: " + todaydate);

//ask database if there any alert for today
try{
exist=AlertDB.upcomingalertfortodayExists(todaydate);
//for testing
System.out.println("Alert for today exist ="+exist);
}finally{
...............
.....................
.....................
 
olivier dutranoit
Ranch Hand
Posts: 81
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Maybe you could work with the GMT time and add or subtract hours to get the indian time?
 
olivier dutranoit
Ranch Hand
Posts: 81
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
something like this :




And if you want the indian time...add or subtract.

 
Stefan Evans
Bartender
Posts: 1780
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The timezone is merely a formatting parameter. You tell the formatter which timezone to print the date in.
If you're adding or subtracting to dates, you're doing it wrong.

why not just:

df.setTimeZone(TimeZone.getTimeZone("GMT+5.5"));
or
df.setTimeZone(TimeZone.getTimeZone("Asia/Colombo"));
 
olivier dutranoit
Ranch Hand
Posts: 81
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:

why not just:

df.setTimeZone(TimeZone.getTimeZone("GMT+5.5"));
or
df.setTimeZone(TimeZone.getTimeZone("Asia/Colombo"));


true
 
Sanchit Sharma
Greenhorn
Posts: 2
Java Netbeans IDE Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think you should change the time of your system according to Indian subcontinent.
 
Tim Moores
Bartender
Posts: 2895
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanchit Sharma wrote:i think you should change the time of your system according to Indian subcontinent.

No. That has an impact way beyond this particular web app, and it most certainly not what is called for.
 
Bhanuprakash Sreenivas
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way is to add the offset for a particular timezone.

TimeZone foreignTimeZone =
TimeZone.getTimeZone("Asia/Colombo");

int offset = -foreignTimeZone.getOffset(Calendar.getInstance().getTimeInMillis());

You can add offset to your local time to get the time of any geography.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic