- import java.sql.Timestamp;
- import java.text.SimpleDateFormat;
- import java.util.TimeZone;
- public class Test {
- public static void main(String[] args) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- long t = System.currentTimeMillis();
- t = t / (1000 * 3600 * 24) * (1000 * 3600 * 24);
- System.out.println(sdf.format(new Timestamp(t)));
- t = System.currentTimeMillis();
- t = t / (1000 * 3600 * 24) * (1000 * 3600 * 24) - TimeZone.getDefault().getRawOffset();
- System.out.println(sdf.format(new Timestamp(t)));
- }
- }
如果不扣掉时区偏移,那么时间将是北京默认的东8区(GMT+8)

本文介绍了一个Java程序示例,展示了如何使用SimpleDateFormat类格式化日期,并通过调整时区偏移来处理时间戳。该示例强调了在进行时间转换时考虑时区的重要性。
1017

被折叠的 条评论
为什么被折叠?



