简体   繁体   中英

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.

I want to convert currentTimeMillis() to Human Readable Format for example "YYMMDDHHMMSS". I am trying to use SimpleDateFormat but it returns LocalTime not 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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM