java中怎么把日期格式化linux在shell中日期格式化

java把日期格式化:

import java.text.SimpleDateFormat;
import java.util.Date;

public class test{

    public static void mainString args[]) {
        Date newTime = new Date);
        //设置时间格式
        SimpleDateFormat sdf1 = new SimpleDateFormat"y-M-d h:m:s a E");
        SimpleDateFormat sdf2 = new SimpleDateFormat"yy-MM-dd hh:mm:ss a E");
        SimpleDateFormat sdf3 = new SimpleDateFormat"yyyy-MMM-ddd hhh:mmm:sss a E");
        SimpleDateFormat sdf4 = new SimpleDateFormat"yyyyy-MMMM-dddd hhhh:mmmm:ssss a E");
        
        //获取的时间,是本机的时间
        String formatDate1 = sdf1.formatnewTime);
        String formatDate2 = sdf2.formatnewTime);
        String formatDate3 = sdf3.formatnewTime);
        String formatDate4 = sdf4.formatnewTime);

        System.out.printlnformatDate1);  
        System.out.printlnformatDate2); 
        System.out.printlnformatDate3); 
        System.out.printlnformatDate4); 
    }
}

输出结果如下:

1.jpg

java中使用SimpleDateFormat类的构造函数SimpleDateFormatString str)构造格式化日期的格式,

通过formatDate date)方法将指定的日期对象格式化为指定格式的字符串.

更多java知识请关注java基础教程。

以上就是java中怎么把日期格式化的详细内容,更多请关注风君子博客其它相关文章!

Published by

风君子

独自遨游何稽首 揭天掀地慰生平