小弟我用这种方法,提取当前时间,如何小时数不对呢
我用这种方法,提取当前时间,怎么小时数不对呢?Date nowDatenew Date()DateFormat dateFormat new Simp
我用这种方法,提取当前时间,怎么小时数不对呢?
Date nowDate=new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date_str = dateFormat.format(nowDate);
应该返回2012-12-19 18:57:27
但是实际返回的是2012-12-19 10:57:27
[解决办法]时区不一样,所以时间不一样
[解决办法]加上这句 dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
[解决办法]Calendar cal = Calendar.getInstance();
String format ="yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(format);
String currentDate = sdf.format(cal.getTime());