zoukankan      html  css  js  c++  java
  • java 时间

    1. package com.grace.test;  
    2.   
    3. import java.text.DateFormat;  
    4. import java.text.ParseException;  
    5. import java.text.SimpleDateFormat;  
    6. import java.util.Calendar;  
    7. import java.util.Date;  
    8.   
    9. public class showDate {  
    10.     public static void main(String[] args) throws ParseException {  
    11.   
    12.         Date d = new Date();  
    13.         String s = null;  
    14.   
    15.         /** 输出格式: Mon May 05 15:23:58 CST 2014 */  
    16.         System.out.println(d);  
    17.   
    18.         /** 输出格式: 2014-5-5 */  
    19.         s = DateFormat.getDateInstance().format(d);  
    20.         System.out.println(s);  
    21.   
    22.         /** 输出格式: 2014-5-5 */  
    23.         s = DateFormat.getDateInstance(DateFormat.DEFAULT).format(d);  
    24.         System.out.println(s);  
    25.   
    26.         /** 输出格式: 2014年5月5日 星期一 */  
    27.         s = DateFormat.getDateInstance(DateFormat.FULL).format(d);  
    28.         System.out.println(s);  
    29.   
    30.         /** 输出格式: 2014-5-5 */  
    31.         s = DateFormat.getDateInstance(DateFormat.MEDIUM).format(d);  
    32.         System.out.println(s);  
    33.   
    34.         /** 输出格式: 14-5-5 */  
    35.         s = DateFormat.getDateInstance(DateFormat.SHORT).format(d);  
    36.         System.out.println(s);  
    37.   
    38.         /** 输出格式: 2014-5-05 00:00:00 大写H为24小时制 */  
    39.         DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
    40.         s = sdf.format(d);  
    41.         System.out.println(s);  
    42.   
    43.         /** 输出格式: 2014-5-05 00:00:00 小写h为12小时制 */  
    44.         DateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");  
    45.         s = sdf2.format(d);  
    46.         System.out.println(s);  
    47.   
    48.         /** 输出格式: 20140505000000 */  
    49.         DateFormat sdf3 = new SimpleDateFormat("yyyyMMddHHmmss");  
    50.         s = sdf3.format(d);  
    51.         System.out.println(s);  
    52.   
    53.         /** 字符串转换城日期格式 */  
    54.         s = sdf.format(d);  
    55.         Date today = sdf.parse(s);  
    56.         System.out.println("字符串转成日期1:" + today);  
    57.         System.out.println("字符串转成日期2:" + sdf.format(today));  
    58.   
    59.         /** 单独输出年月日时分秒等 */  
    60.         Calendar c = Calendar.getInstance();  
    61.         System.out.println("年: " + c.get(Calendar.YEAR));  
    62.         // 月份从0开始,加1校正  
    63.         System.out.println("月: " + (c.get(Calendar.MONTH) + 1) + "");  
    64.         System.out.println("日: " + c.get(Calendar.DAY_OF_MONTH));  
    65.         System.out.println("时: " + c.get(Calendar.HOUR_OF_DAY));  
    66.         System.out.println("分: " + c.get(Calendar.MINUTE));  
    67.         System.out.println("秒: " + c.get(Calendar.SECOND));  
    68.         System.out.println("当前时间毫秒数:" + c.getTimeInMillis());  
    69.         System.out.println("当前时间: " + c.getTime());  
    70.     }  
    71. }  
  • 相关阅读:
    效率分页代码
    serialPort控件(串口通信)
    C#事件DEMO
    泛型类
    简单的登陆页面
    hdu 1342+hdu 2660+hdu 2266+hdu 1704+hdu 1627+hdu 1539
    hdu 3987(求割边最小的最小割)
    hdu 1907(尼姆博弈)
    hdu 2149+hdu 1846(巴什博弈)
    hdu 2516(斐波那契博弈)
  • 原文地址:https://www.cnblogs.com/xiaojiayu/p/5415768.html
Copyright © 2011-2022 走看看