Archive for March, 2011

How to convert local timestamp to UTC in Java?

The below code can be used to convert the local timestamp to UTC in Java.  Converting to any other timezone is very easy by changing the below UTC into the target timezone. public static String getCurrentUTCTimestamp() { SimpleDateFormat dateFormatter = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss z”); final TimeZone utc = TimeZone.getTimeZone(“UTC”); dateFormatter.setTimeZone(utc); return dateFormatter.format(new java.util.Date()); }