- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
- dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+08:00")); // 不会受系统时区设置的影响,否则时间可能不准确
- currentTime = dateFormat.format(System.currentTimeMillis());
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+08:00")); //加上这行代码就哦了
加上 dateFormat.setTimeZone 就万事大吉了。。。 不会受系统时区设置的影响了
本文介绍如何使用Java中的SimpleDateFormat类进行日期格式化,并确保不受系统时区影响的方法。通过设置固定时区(如GMT+08:00),可以避免因不同设备时区设置差异导致的时间显示错误。
1294

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



