有需求或技術問題可以隨時跟我連絡 (MSN上線時)

2011年7月19日 星期二

LocalTime to UTC in JAVA

import java.text.SimpleDateFormat; 
import java.util.Date;
import java.util.TimeZone;
 
public class scratch {
    public static void main (String args[]) {
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
        sdf.setTimeZone (TimeZone.getTimeZone ("UTC"));
        System.out.println ("Time in UTC is " + sdf.format (now));
    }
}


This outputs:



Time in UTC is 2011-04-11 13:40:04 

沒有留言:

張貼留言