SimpleDateFormat in Android giving unwanted time zone in Android 1.6
Given the following:
String dt = "Wed Jan 1 12:34:03 2010";
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy");
Date output =开发者_StackOverflow sdf.parse(dt);
Produces:
Wed Jan 1 12:34:03 ADT 2010
Where is the timezone coming from? I don't have z in my format pattern.
Thanks, Doug
You're apparently displaying the toString()
outcome of the Date
object like as
System.out.println(output);
The format is specified in the javadoc and it indeed includes the timezone.
toString
public String toString()
Converts this
Date
object to aString
of the form:dow mon dd hh:mm:ss zzz yyyy
You need SimpleDateFormat#format()
to convert the obtained Date
object to a String
in the desired format before representing it. For example,
String s = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(output);
System.out.println(s); // 01-01-2010 12:34:03
When a Date object is created, the timezone is set from the system settings.
try output.getTimeZoneoffset() and it returns the offset in minutes (for ADT it's -180)
精彩评论