實際開發了,爲了快速查詢,咱們會把日期以Long類型的方式存儲到數據庫中,好比20000000000000L,但顯示的時候,要完整的日期,即yyyy-MM-dd的格式顯示。數據庫
這個時候,咱們就能夠使用Collections2.transform方法處理相似的狀況。spa
HashSet<Long> set = Sets.newHashSet(); set.add(20000000000000L); set.add(30000000000000L); set.add(40000000000000L); Collection<String> result2 = Collections2.transform(set, input -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(input).toString()); result2.forEach(System.out::println);
輸出code
2603-10-11 19:33:20
3237-07-20 07:06:40
2920-08-30 13:20:00orm