zoukankan      html  css  js  c++  java
  • Date类的用法

    package example;
    
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    public class Test {
    
        /**
         * @throws ParseException 
         * 
         */
        public static void main(String[] args) throws ParseException {
            //当前时间毫秒值
            long time=System.currentTimeMillis();
            System.out.println(time);//output:1458319364610
            
            //当前时间和日期封装成Date对象
            Date date1=new Date();
            System.out.println(date1);//output:Sat Mar 19 00:42:44 CST 2016
            
            //将毫秒值封装为Date对象
            Date date2=new Date(time);
            System.out.println(date2);//output:Sat Mar 19 00:42:44 CST 2016
            
            //通过date对象获得毫秒值
            long time2=date2.getTime();
            System.out.println(time2);//output:1458319364610
            
            //获取日期格式对象
            DateFormat df=DateFormat.getDateInstance(DateFormat.FULL);
            String strdate1=df.format(date1);
            System.out.println(strdate1);//2016年3月19日 星期六
            
            //自定义风格
            df=new SimpleDateFormat("YYYY年--MM月--dd日");
            String strdate2=df.format(date1);
            System.out.println(strdate2);//2016年--03月--19日
            
            //字符串变日期对象
            String strdate3="2015年2月10日";
            DateFormat df3=DateFormat.getDateInstance(DateFormat.LONG);
            Date date3=df3.parse(strdate3);
            System.out.println(date3);//Tue Feb 10 00:00:00 CST 2015
        }
    }
  • 相关阅读:
    linux实践——内核编程 基础模块
    linux内核分析 课程总结
    linux内核分析 期中总结
    linux内核分析 第八周
    linux内核分析 第4章读书笔记
    linux内核分析 第七周
    2020JAVA面试题
    springboot redis工具类
    mysql关于时间函数的应用
    jetty的web部署
  • 原文地址:https://www.cnblogs.com/xurui1995/p/5289810.html
Copyright © 2011-2022 走看看