zoukankan      html  css  js  c++  java
  • 指定java中Date日期格式化,实现字符串转Date

     日期格式化

    y 代表年  M 代表月   d 代表日

    E 代表星期

    H 代表24进制的小时   m 代表分钟   s 代表秒     S 代表毫秒

    h 代表12进制的小时

    public class DateTest {
    
        public static void main(String[] args) {
    
           SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    
           Date date=new Date();
    
           String dateStr=sdf.format(date);
    
           System.out.println(dateStr);
    
        }

    字符串转日期

    public class DateTest {
    
        public static void main(String[] args) {
    
           SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    
           String str="2020/10/13 10:11:12";
    
           try {
    
               Date date=sdf.parse(str);
    
               System.out.println("字符串:"+str+"通过yyyy/MM/dd HH:mm:ss格式转换得到"+date.toString());  }
        
    catch (ParseException e)
              {
    e.printStackTrace(); } } }
  • 相关阅读:
    053532
    053531
    053530
    053529
    053528
    RTSP和RTMP的区别是什么?
    RTSP、RTMP和HTTP协议的区别
    在C#中实现视频播放器
    wpf下基于opencv实现视频播放器
    C#实现视频播放器(Vlc.DotNet)
  • 原文地址:https://www.cnblogs.com/itjone/p/13811884.html
Copyright © 2011-2022 走看看