Java 获取UTC时间

几行代码而已,百度上各种代码都有,各种格式,我还是写自己的吧。

import java.util.Date;

public class Main
{

	public static void main(String[] args)
	{
		// TODO Auto-generated method stub

		Date time_now = new Date();
		@SuppressWarnings("deprecation")
		long time_code = Date.UTC(
				time_now.getYear(), 
				time_now.getMonth(),
				time_now.getDate(), 
				time_now.getHours(), 
				time_now.getMinutes(),
				time_now.getSeconds());
		Date time_utc = new Date(time_code); 
		System.out.println(time_utc.toString());
	}
}


你可能感兴趣的:(java,Date,UTC)