date简述
Date?
定義時(shí)間和日期的類? ?java.util.Date? ??
1s=1000ms;
時(shí)間的原點(diǎn):公元1970年1月1日 00點(diǎn)00分00秒;
public class DateDemo {public static void main(String[] args) {fun();}private static void fun() {Date d=new Date(0);System.out.println(d);//Thu Jan 01 08:00:00 CST 1970 } }date相關(guān)練習(xí):
import java.text.SimpleDateFormat; import java.util.Date;public class DateDemo {public static void main(String[] args) {fun();fun2();fun3();}private static void fun3() {//將毫秒轉(zhuǎn)化成日期格式Date d=new Date(100000000000L);System.out.println(d);///Sat Mar 03 17:46:40 CST 1973//將日期格式轉(zhuǎn)換成毫秒Date d1=new Date();//獲得當(dāng)前時(shí)間long t=d1.getTime();//將日期格式轉(zhuǎn)換為毫秒System.out.println(t);//1552985210470 d1.setTime(3000000000000L);//setTime方法將毫秒值轉(zhuǎn)日期格式System.out.println(d1);//Sat Jan 24 13:20:00 CST 2065 }private static void fun2() {SimpleDateFormat d=new SimpleDateFormat("yyyy年MM月dd日HH時(shí)mm分ss秒");//yyyy年MM月dd日HH時(shí)mm分ss漢字可以改但是里面的字母不能改String s=d.format(new Date());//將當(dāng)前時(shí)間轉(zhuǎn)換成字符串形式 System.out.println(s);//2019年03月19日16時(shí)42分01秒 }private static void fun() {Date d=new Date(0);//獲取時(shí)間的原點(diǎn)System.out.println(d);//Thu Jan 01 08:00:00 CST 1970Date d1=new Date();//獲取當(dāng)前時(shí)間System.out.println(d1);//Tue Mar 19 16:42:01 CST 2019 } }?
轉(zhuǎn)載于:https://www.cnblogs.com/Zs-book1/p/10559731.html
總結(jié)
- 上一篇: Django之管理权限
- 下一篇: [leetcode-108,109] 将