zoukankan      html  css  js  c++  java
  • java常用类-------Date类和DateFormat类

    package cn.zxg.PackgeUse;

    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;

    /**
    * 测试时间对象和字符串之间的转换
    * DateFormat抽象类和SimpleDateFormat实现类的使用
    */

    public class TestFormat {
    public static void main(String[] args) throws ParseException {
    //把时间按照"格式字符串指定的格式"转换成对应的字符串
    DateFormat df=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    String str=df.format(new Date());
    System.out.println(str);

    //把字符串按照"格式字符串指定的格式"转换成对应的时间
    DateFormat df2=new SimpleDateFormat("yyyy年MM月dd日 hh时mm分ss秒");

    Date date=df2.parse("1990年01月18日 12时30分35秒");
    System.out.println(date);
    //测试其他格式字符,比如用D测试今天处于当年第几天
    DateFormat df3=new SimpleDateFormat("D");
    String str3=df3.format(new Date());
    System.out.println(str3);



    }
    }
  • 相关阅读:
    POJ 2723 Get Luffy Out(2-SAT)
    ZOJ 3613 Wormhole Transport
    HDU 4085 Peach Blossom Spring
    NBUT 1221 Intermediary
    NBUT 1223 Friends number
    NBUT 1220 SPY
    NBUT 1218 You are my brother
    PAT 1131. Subway Map (30)
    ZSTU OJ 4273 玩具
    ZSTU OJ 4272 最佳淘汰算法
  • 原文地址:https://www.cnblogs.com/zzzao/p/10903645.html
Copyright © 2011-2022 走看看