views:

87

answers:

4

Hi I am looking to set the timezone for San Antonio, Texas.Can some please tell me how do i set the same in my Java code.

I want it in the format somewhat similar to America/New York

Currently I am using

TimeZone.getTimeZone("America/Denver")

But "America/Denver" doesn't seem to be the right timezone for San Antonio, Texas

A: 

I totally googled your question and got this: http://www.few.vu.nl/~eliens/documents/java/jdk1.2-docs/docs/api/java/util/TimeZone.html

You can also get a TimeZone using getTimeZone along with a time zone ID. For instance, the time zone ID for the Pacific Standard Time zone is "PST". So, you can get a PST TimeZone object with:

TimeZone tz = TimeZone.getTimeZone("PST");

halfevil
On the other hand, if you look at more recent docs you'll see: *Note that the support of abbreviations is for JDK 1.1.x compatibility only and full names should be used.*
Jon Skeet
A: 
Date today = new Date();

// Get all time zone ids
String[] zoneIds = TimeZone.getAvailableIDs();

// View every time zone
for (int i=0; i<zoneIds.length; i++) {
    // Get time zone by time zone id
    TimeZone tz = TimeZone.getTimeZone(zoneIds[i]);

    // Get the display name
    String shortName = tz.getDisplayName(tz.inDaylightTime(today), TimeZone.SHORT);
    String longName = tz.getDisplayName(tz.inDaylightTime(today), TimeZone.LONG);

    // Get the number of hours from GMT
    int rawOffset = tz.getRawOffset();
    int hour = rawOffset / (60*60*1000);
    int min = Math.abs(rawOffset / (60*1000)) % 60;

    // Does the time zone have a daylight savings time period?
    boolean hasDST = tz.useDaylightTime();

    // Is the time zone currently in a daylight savings time?
    boolean inDST = tz.inDaylightTime(today);
}  

This will list out all supported TimeZone.
You can select yours and set it like

Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan"));
japanCal.setTimeInMillis(local.getTimeInMillis());  

source: http://www.exampledepot.com/egs/java.util/GetTimeOtherZone2.html

org.life.java
A: 

related topic: http://stackoverflow.com/questions/230126/how-to-handle-calendar-timezones-using-java

timezone for San Antonio:
Standard time zone: UTC/GMT -6 hours
Daylight saving time: +1 hour
Current time zone offset: UTC/GMT -5 hours
Time zone abbreviation: CDT - Central Daylight Time

edit: this link is better in regards to America/New York format: http://stackoverflow.com/questions/1694885/timezones-in-java

chrismh
A: 

For San Antonio, you should use TimeZone.getTimeZone("US/Central")

If you really need to use "America/<City>" format, the closest to San Antonio us city is "America/Chicago".

You can use this to get a list of all available specific IDs for US/Central:

String[] values = TimeZone.getAvailableIDs(TimeZone.getTimeZone("US/Central").getRawOffset());

And then, double check here:

http://www.timeanddate.com/library/abbreviations/timezones/na/cst.html

Leo Holanda