zoukankan      html  css  js  c++  java
  • SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS")时间转换问题

    SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS")时间转换问题

    • 程序代码:

        import java.text.ParseException;
        import java.text.SimpleDateFormat;
        import java.util.Date;
      
        public class Time {
        public static void main(String[] args) throws ParseException {
        //定义一个时间字符串
        String date_str = "2016-06-23 09:46:27.000";
        //将时间字符串转换成Date形式,不能够强制转换
        Date date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS").parse(date_str);
        //定义新的字符串str1和str2,将Date型转为String型
        String str1 = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
        String str2 = (new SimpleDateFormat("yyyy年MM月dd日 ")).format(date);
        
        //取当前时间进行修改,方法1
        String str3 = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date());
        //取当前时间进行修改,方法2,其实和方法1类似
        SimpleDateFormat format=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
        String str4 = format.format(new Date());
                System.out.println("str1:	"+str1);
        System.out.println("str2:	"+str2);
        System.out.println("str3:	"+str3);
        System.out.println("str4:	"+str4);
        	}	
        }
      
    • 输出:

  • 相关阅读:
    保险精算导论
    天津大学C语言程序设计
    会计学
    WIN10 CH340安装失败
    好用的浏览器插件
    好用的壁纸软件
    30讲 窗口看门狗
    STM32替换Arduino直通车
    stm32系列芯片独立看门狗(IWDG)溢出时间计算原理
    AD 电子元器件图片、名称及符号对照
  • 原文地址:https://www.cnblogs.com/renxiuxing/p/9194003.html
Copyright © 2011-2022 走看看