两种格式化日期的方法,你更喜欢哪一种?

来源:互联网 发布:云南白药法律知乎 编辑:程序博客网 时间:2024/05/21 10:47
import java.text.SimpleDateFormat;import java.util.Date;
public class Test{public static void main(String[] args){//使用格式说明符格式化日期//格式化日期:新的写法     Date date=new Date(); String yearMonthDay=String.format("%tF",date); String hourMinuteSecond=String.format("%tT",date);     System.out.println("现在是:"+yearMonthDay+" "+hourMinuteSecond);     System.out.println("===================================");     //使用熟悉的格式化字符串的方法     SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  String fullTime=sdf.format(date);    System.out.print("现在是:"+fullTime);}}

原创粉丝点击