zoukankan      html  css  js  c++  java
  • SimpleDateFormat类

    • A:DateFormat类的概述
      • DateFormat 是日期/时间格式化子类的抽象类,它以与语言无关的方式格式化并解析日期或时间。是抽象类,所以使用其子类SimpleDateFormat
    • B:SimpleDateFormat构造方法
      • public SimpleDateFormat()
      • public SimpleDateFormat(String pattern)
    • C:成员方法
      • public final String format(Date date)
      • public Date parse(String source)

    package com.loaderman.otherclass;
    
    import java.text.DateFormat;
    
    import java.text.ParseException;
    
    import java.text.SimpleDateFormat;
    
    import java.util.Date;
    
     
    public class Demo7_SimpleDateFormat {
    
       /**
    
        * * A:DateFormat类的概述
    
             * DateFormat 是日期/时间格式化子类的抽象类,它以与语言无关的方式格式化并解析日期或时间。是抽象类,所以使用其子类SimpleDateFormat
    
          * B:SimpleDateFormat构造方法
    
             * public SimpleDateFormat()
    
             * public SimpleDateFormat(String pattern)
    
          * C:成员方法
    
             * public final String format(Date date)
    
             * public Date parse(String source)
    
        * @throws ParseException 
    
        */
    
       public static void main(String[] args) throws ParseException {
    
          //demo1();
    
          //demo2();
    
          //demo3();
    
          //将时间字符串转换成日期对象
    
          String str = "2000年08月08日 08:08:08";
    
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
    
          Date d = sdf.parse(str);                //将时间字符串转换成日期对象
    
          System.out.println(d);
    
       }
       public static void demo3() {
    
          Date d = new Date();                    //获取当前时间对象
    
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");//创建日期格式化类对象
    
          System.out.println(sdf.format(d));          //将日期对象转换为字符串
    
       }
       public static void demo2() {
    
          Date d = new Date();                    //获取当前时间对象
    
          SimpleDateFormat sdf = new SimpleDateFormat(); //创建日期格式化类对象
    
          System.out.println(sdf.format(d));         //88-6-6 下午9:31
    
       }
       public static void demo1() {
    
          //DateFormat df = new DateFormat();            //DateFormat是抽象类,不允许实例化
    
          //DateFormat df1 = new SimpleDateFormat();
    
          DateFormat df1 = DateFormat.getDateInstance(); //相当于父类引用指向子类对象,右边的方法返回一个子类对象
    
       }
    }
    
     
    
  • 相关阅读:
    vue 监听变量或对象
    同行span标签设置display:inline-block;overflow:hidden垂直对齐问题
    vue style 的scoped 使用
    判断两个对象是否相等
    js call 和 apply方法记录
    接口联调遇到的坑 总结
    onclick或者其他事件在部分移动端无效的问题
    js 迭代方法
    原生js实现类的添加和删除,以及对数据的add和update、view ,ajax请求 ,页面离开的操作,获取url中参数等方法
    input 的radio checkbox 和 select 相关操作
  • 原文地址:https://www.cnblogs.com/loaderman/p/6407231.html
Copyright © 2011-2022 走看看