[英]Java System.currentTimeMillis() in Human Readable Format UTC
Similar question might be asked many times but I couldn't find question which ask for Human Readable Format in UTC time. 类似的问题可能被问过很多次,但是我找不到在UTC时代要求人类可读格式的问题。
I want to convert currentTimeMillis() to Human Readable Format for example "YYMMDDHHMMSS". 我想将currentTimeMillis()转换为人类可读格式,例如“ YYMMDDHHMMSS”。 I am trying to use SimpleDateFormat but it returns LocalTime not UTC.
我正在尝试使用SimpleDateFormat,但它返回的是LocalTime,而不是UTC。
long currentTimeMillis = System.currentTimeMillis();
DateFormat dateFormat = new SimpleDateFormat("yyMMddHHmm");
Date date = new Date(currentTimeMillis);
String currentTime = dateFormat.format(date);
this code gives me LocalTime but I want time in UTC only. 这段代码为我提供了LocalTime,但我只想使用UTC时间。
It may help you. 它可能会帮助您。 If not get back with problem.
如果没有问题。
long currentTimeMillis = System.currentTimeMillis();
DateFormat dateFormat = new SimpleDateFormat("yy/MM/dd HH:mm");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = new Date(currentTimeMillis);
String currentTime = dateFormat.format(date);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.