zoukankan      html  css  js  c++  java
  • java Date中方法toLocaleString过时的替代方案

    Java代码  
    1.System.out.println(new java.util.Date());  
    输出:Thu Jan 27 14:43:28 CST 2011

    2.System.out.println(new java.util.Date().toLocaleString());  
    输出:2011-1-27 14:45:21

    不过现在toLocaleString()方法已过时,由DateFormat.format(Date date)取代。
    DateFormat ddf = DateFormat.getDateInstance();  
    DateFormat dtf = DateFormat.getTimeInstance();  
    DateFormat ddtf = DateFormat.getDateTimeInstance();  
    Date date = new Date();  
    System.out.println("日期:" + ddf.format(date));  
    System.out.println("时间:" + dtf.format(date));  
    System.out.println("日期时间:" + ddtf.format(date));  
    SimpleDateFormat sdf = (SimpleDateFormat) DateFormat.getDateTimeInstance();  
    System.out.println("日期时间:" + sdf.format(date)); 

     输出:

     日期:2011-2-9

    时间:11:16:02

    日期时间:2011-2-9 11:16:02

    日期时间:2011-2-9 11:16:02

      

  • 相关阅读:
    iota妙用
    io
    http
    gosched
    go设置使用多少个cpu
    go协程的特点
    go条件变量同步机制
    Go奇技淫巧
    U5首次登录
    Maven安装中的问题
  • 原文地址:https://www.cnblogs.com/taomylife/p/8042267.html
Copyright © 2011-2022 走看看