Reading system time in CST time zone using Java -


i trying read system date in cst time zone using java. tried below code whenever use formatter.parse() returning time in est time zone.

private date gettodayincst() {     calendar currentdate = calendar.getinstance();     dateformat formatter = new simpledateformat("dd-mm-yyyy hh:mm:ss");     timezone obj = timezone.gettimezone("cst");     formatter.settimezone(obj);      string today = formatter.format(currentdate.gettime());     try {         return formatter.parse(today);     } catch (parseexception e) {         e.printstacktrace();     }     return null; } 

java.util.date objects not contain timezone information - cannot set timezone on date object. thing date object contains number of milliseconds since "epoch" - 1 january 1970, 00:00:00 utc.

if want set timezone try way

simpledateformat format = new simpledateformat("yyyy-mm-dd hh:mm:ss z"); format.settimezone(timezone.gettimezone("cst")); system.out.println(format.format(new date())); 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -