我寫了一個測試直到測試許可證密鑰的有效性..並在同一時間,更新代碼以使用Java 8 java.time包。DateTimeFormatter格式化失敗
所以..創造一個「有效期至」日期時間和格式,爲的字符串:
LocalDateTime now = LocalDateTime.now(Clock.systemUTC());
LocalDateTime nowPlus1Hour = now.plusHours(1);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
formatter = formatter.withZone(Clock.systemUTC().getZone());
String validUntilString = nowPlus1Hour.format(formatter);
這個..大部分工作。 (我的最後一個版本拋出異常,因爲我沒有創建一個formatter'withZone'。)
但是,'validUntilString'的值是'2015-05-19 19:46:26 Z'真的。 'Z'。來吧!
因此..給定一個LocalDateTime,你如何得到一個字符串,包括(是的,ambigious,但在這種情況下UTC,一個標準)時區ID?
Z是UTC的同義詞。你對我看起來很好。見http://www.timeanddate.com/time/zones/z和http://en.wikipedia.org/wiki/Coordinated_Universal_Time#Time_zones –
好吧..現在我不覺得愚蠢。 – ticktock
Z代表祖魯時間 – bowmore