Java统计从1970年1月1日起的毫秒的数量表示日期。也就是说,例如,1970年1月2日,是在1月1日后的86,400,000毫秒。但是程序结果却不是如此,纳闷!!import java.text.ParseException;
import java.text.SimpleDateFormat;public class Test2 {
public static void main(String[] args) {
// TODO
String sDay = "1970-01-01";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try {
java.util.Date d1 = sdf.parse(sDay);
System.out.println(d1.getTime());
} catch (ParseException e) {
System.out.println(e);
} }
}
程序返回结果: 57600000请大家帮忙分析一下。
import java.text.SimpleDateFormat;public class Test2 {
public static void main(String[] args) {
// TODO
String sDay = "1970-01-01";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try {
java.util.Date d1 = sdf.parse(sDay);
System.out.println(d1.getTime());
} catch (ParseException e) {
System.out.println(e);
} }
}
程序返回结果: 57600000请大家帮忙分析一下。
但你这个是时区问题,你把你的时区改成GMT应该就行了
和北京时间差8个小时,呵呵
public static void main(String[] args) {
long totalMilliseconds = System.currentTimeMillis();
long totalSeconds = totalMilliseconds / 1000;
int currentSecond = (int)(totalSeconds % 60);
long totalMinutes = totalSeconds / 60;
int currentMinute = (int)(totalMinutes % 60);
long totalHours = totalMinutes / 60;
int currentHour = (int)(totalHours % 24);
String output = "Current time is " + currentHour + ":"
+ currentMinute + ":" + currentSecond + "GMT";
JOptionPane.showMessageDialog(null, output,
"showCurrentTime",JOptionPane.INFORMATION_MESSAGE);
}
}
String sDay = "1970-01-01 GMT";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd z");
……结果得到正确的0