zoukankan      html  css  js  c++  java
  • simpleDateFormat日期格式转换

     

    1-------------------------------------------------------------------------------------

    package com.neusoft.date;

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

    public class SimpleDateFormat01
    {

        public static void main(String[] args) throws ParseException
        {
            // TODO Auto-generated method stub
          String str = "2009-02-15 09:21:35.345";
          SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
          SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日 hh时mm分ss秒SSS毫秒");
          Date date = sdf1.parse(str);//提取格式中的日期
          System.out.println("转换之前的日期:"+date);
          String newStr = sdf2.format(date); //改变格式
          System.out.println("转换之后的日期:"+newStr);
           
        }

    }

    2-------------------------------------------------------------------------------------

    package com.neusoft.date;

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

    public class SimpleDateFormatDemo02
    {
     public static void main(String []args) throws ParseException{
        String str = "2009-02-15 09:21:35.345";//接收參数
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy年MM月dd日");
        Date date = sdf.parse(str);//提取格式中的日期
        String str1 = sdf1.format(date);
        System.out.println(date);
        System.out.println(str1);
       
     }
    }

    3-------------------------------------------------------------------------------------

    package com.neusoft.date;

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

    public class SimpleDateFormatDemo03
    {
        SimpleDateFormat sdf = null;
        //2012-03-05
        public String DateFormat(){
            this.sdf = new SimpleDateFormat("yyyy-MM-dd");
            String str = this.sdf.format(new Date());
            return str;
        }
        //2012-03-05 05:27:15:390
        public String DateFormat1(){
            this.sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS");
            String str = this.sdf.format(new Date());
            return str;
        }
        //2012年03月05日
        public String dateNewFormat(){
            this.sdf = new SimpleDateFormat("yyyy年MM月dd日");
            String str = this.sdf.format(new Date());
            return str;
        }
        //2012年03月05日05时26分19秒437毫秒
        public String dateNewFormat1(){
            this.sdf = new SimpleDateFormat("yyyy年MM月dd日hh时mm分ss秒SSS毫秒");
            String str = this.sdf.format(new Date());
            return str;
        }
        public String dateNewFormat2(){
            this.sdf = new SimpleDateFormat("yyyyMMddhhmmssSSS");
            String str = this.sdf.format(new Date());
            return str;
        }
     public static void main(String []args) throws ParseException{
         SimpleDateFormatDemo03 ss= new SimpleDateFormatDemo03();
         System.out.println(ss.DateFormat());
         System.out.println(ss.DateFormat1());
         System.out.println(ss.dateNewFormat());
         System.out.println(ss.dateNewFormat1());
         System.out.println(ss.dateNewFormat2());
     }
    }

  • 相关阅读:
    wince串口打印信息的屏蔽与打开
    2440 6.0BSP 移植过程之OAL
    2440 6.0BSP移植过程之电池驱动
    2440 6.0BSP移植过程之SD卡驱动
    如何在wince6.0 模拟器上跑以前编译好的EVC MFC程序
    2440 休眠唤醒的实现过程(作者:wogoyixikexie@gliet)
    CETK的使用(USB连接方式)
    如何扩展ARM内存(OEMGetExtensionDRAM和pNKEnumExtensionDRAM函数可以解决问题)
    ZLG7290(wince下)驱动之不停执行同一动作的解决办法(作者:wogoyixikexie@gliet)
    2440 中断优先级问题(作者wogoyixikexie@gliet)
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4565934.html
Copyright © 2011-2022 走看看