Java format utc time

From snippet wiki
Jump to navigation Jump to search

Getting an UTC zoned time from java can be a challange. Just don't rely on the Date object itself, but use something like this:

ZonedDateTime utc = ZonedDateTime.now(ZoneOffset.UTC);
String sDate = utc.format(DateTimeFormatter.ofPattern("MMddHHmmyy"));

Which gives you back a nice command line argument for the busybox date command. Whoever made that crime of syntax.