项目需要把 long 转换成 Timestamp,而且需要是 UTC 时间格式。
网上 google了好久,总结了这个写法
Calendar cal = Calendar.getInstance(); long value = cal.getTimeInMillis(); //your long value. int zoneOffset = cal.get(Calendar.ZONE_OFFSET); int dstOffset = cal.get(Calendar.DST_OFFSET); cal.setTimeInMillis(value); cal.add(Calendar.MILLISECOND, -(zoneOffset+dstOffset)); //it only takes int int System.out.println(new Timestamp(cal.getTimeInMillis()));