• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Server in canada but need Indian date and time

 
Greenhorn
Posts: 14
Oracle Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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{
...............
.....................
.....................
 
Ranch Hand
Posts: 81
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
something like this :




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

 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 2
Netbeans IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think you should change the time of your system according to Indian subcontinent.
 
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic