• 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());
     }
    }

  • 相关阅读:
    Android Push Notification实现信息推送使用
    线段树 Interval Tree
    树状数组
    LCA和RMQ
    RMQ (Range Minimal Query) 问题 ,稀疏表 ST
    winner tree 胜者树
    ORA-64379: Action cannot be performed on the tablespace assigned to FastStart while the feature is enabled
    mybatis 查询优化主子表查询之association和collection
    Oracle 11gR2 用户重命名(rename user)
    redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: 断开的管道 (Write failed)
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4565934.html
Copyright © 2020-2023  润新知