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);
        	}	
        }
      
    • 输出:

  • 相关阅读:
    SpringBoot(十二)------国际化配置
    SpringBoot(十一) ----SpringBoot结合mybatis实现增删改查
    SpringBoot(十)----SpringMVC自动配置&扩展配置
    SpringBoot学习(九) ------访问静态web资源
    leetcode-----两数相加
    JDBC — 学习大纲
    网络编程
    StringBuffer
    代理
    加载文件的两种方式
  • 原文地址:https://www.cnblogs.com/renxiuxing/p/9194003.html
Copyright © 2011-2022 走看看