zoukankan      html  css  js  c++  java
  • Java基础之Date对象的使用

    import java.util.*;
    import java.text.*;
    class DateDemo
    {
        public static void main(String[] args)
        {
            Date d = new Date();
            sop(d);
            
            /*
                日期格式化:
                将模式封装到SimpleDateFormat对象中。
                
                字母  日期或时间元素  表示  示例  
                --------------------------------------------------
                G  Era 标志符  Text  AD  
                y  年  Year  1996; 96  
                M  年中的月份  Month  July; Jul; 07  
                w  年中的周数  Number  27  
                W  月份中的周数  Number  2  
                D  年中的天数  Number  189  
                d  月份中的天数  Number  10  
                F  月份中的星期  Number  2  
                E  星期中的天数  Text  Tuesday; Tue  
                a  Am/pm 标记  Text  PM  
                H  一天中的小时数(0-23)  Number  0  
                k  一天中的小时数(1-24)  Number  24  
                K  am/pm 中的小时数(0-11)  Number  0  
                h  am/pm 中的小时数(1-12)  Number  12  
                m  小时中的分钟数  Number  30  
                s  分钟中的秒数  Number  55  
                S  毫秒数  Number  978  
                z  时区  General time zone  Pacific Standard Time; PST; GMT-08:00  
                Z  时区  RFC 822 time zone  -0800  

            
    */
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:S E");
            
            /*调用format方法让模式格式化指定Date对象*/
            sop(simpleDateFormat.format(d));
            
            sop(new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒S毫秒").format(new Date()));
        }
        
        public static void sop(Object obj)
        {
            System.out.println(obj);
        }
    }
  • 相关阅读:
    select @@identity的用法
    类的实践
    UVA 1572 SelfAssembly(图论模型+拓扑排序)
    UVA 10562 Undraw the Trees(多叉树的dfs)
    sprintf与sscanf用法举例
    UVA 10129 Play on Words(欧拉回路)
    UVA 816 Abbott's Revenge(bfs)
    递增【二分】
    递增【二分】
    递增【二分】
  • 原文地址:https://www.cnblogs.com/cxmsky/p/2879913.html
Copyright © 2011-2022 走看看