Cheug's Blog

当前位置:网站首页 / JAVA / 正文

Date类

2019-03-24 / JAVA / 798 次围观 / 0 次吐槽 /

日期类

             Date date = new Date();    //表示当前的时间

             date.getTime();方法返回的自1970-1-1到现在走的毫秒数(时间戳)

        掌握把毫秒数 转成 Date

             long time = 123412341234123L;

             Date date = new Date(time);

SimpleDateFormat

        SimpleDateFormat是DateFormat的子类,DateFormat是一个抽象类

        SimpleDateFormat把 Date 转成固定格式的字符串时间

                  Date date = new Date();

                  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                  String str = sdf.format(date);

        SimpleDateFormat把 字符串时间 转成 Date

                  String str = "2018-02-02 17:00:23";

                  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                  Date date = sdf.parser(str);

                  image.png

额 本文暂时没人评论 来添加一个吧

发表评论

必填

选填

选填

必填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Cheug's Blog

Copyright Cheug Rights Reserved.