Skip to content

Instantly share code, notes, and snippets.

@alvintamie
Last active August 29, 2015 14:13
Show Gist options
  • Save alvintamie/5a692454d588b187cd47 to your computer and use it in GitHub Desktop.
Save alvintamie/5a692454d588b187cd47 to your computer and use it in GitHub Desktop.
Java Parse Time with Timezone
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.TimeZone;
public class ParseTimeWithTimezone{
public static void main(String []args){
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
Date date = sdf.parse("2015-01-16T09:00:00.000+08:00");
sdf.setTimeZone(TimeZone.getTimeZone("Asia/Singapore"));
System.out.println(sdf.format(date));
}
catch (Exception e) {
//The handling for the code
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment