java程序中设置时区

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class Test {
     public static void main(String[] args) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            //TimeZone timeZoneChina = TimeZone.getTimeZone("Asia/Shanghai");
            //format.setTimeZone(timeZoneChina);
            //设置系统时区
            String date = format.format(new Date());
            System.out.println(date);
             System.out.println(System.getProperty("user.timezone"));
       }
}

你可能感兴趣的:(java)