File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Server in canada but need Indian date and time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Server in canada but need Indian date and time" Watch "Server in canada but need Indian date and time" New topic
Author

Server in canada but need Indian date and time

Prady Kural
Greenhorn

Joined: Feb 16, 2011
Posts: 14

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

Joined: Aug 20, 2011
Posts: 81

Hi,

Maybe you could work with the GMT time and add or subtract hours to get the indian time?
olivier dutranoit
Ranch Hand

Joined: Aug 20, 2011
Posts: 81

something like this :




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

Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
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

Joined: Aug 20, 2011
Posts: 81

Stefan Evans wrote:

why not just:

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


true
Sanchit Sharma
Greenhorn

Joined: Jul 17, 2010
Posts: 2

i think you should change the time of your system according to Indian subcontinent.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Jan 01, 2010
Posts: 8
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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Server in canada but need Indian date and time