Java中的时间函数
Java提供了java.util包中可用的Date类,该类封装了当前日期和时间。可以从java.util.Date类访问时间函数。这代表毫秒精度的时间实例。
Java中的时间函数之一是getTime()函数。它返回自格林尼治标准时间1970年1月1日00:00:00以来经过的毫秒数。演示此的程序如下所示-
示例
import java.util.*;
public class Example {
public static void main(String[] args) {
Date d = new Date(95, 7, 15);
long num = d.getTime();
System.out.println("From the date 1-1-1970 to the date 15-07-1995, " + num + " 毫秒已过去。");
}
}输出结果
From the date 1-1-1970 to the date 15-07-1995, 808444800000 毫秒已过去。
现在让我们了解上面的程序。
首先,创建一个日期。然后使用该函数getTime()查找自格林尼治标准时间1970年1月1日00:00:00以来经过的毫秒数。然后显示。证明这一点的代码片段如下所示-
Date d = new Date(95, 7, 15);
long num = d.getTime();
System.out.println("From the date 1-1-1970 to the date 15-07-1995, " + num + " 毫秒已过去。");热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短