package com.page2;
import java.text.*;
import java.util.Date;
public class demodate {
public static void main(String args[]) {
SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd");
String input = args.length == 0 ? "1818-11-11" : args[0];
System.out.print(input + " Parses as ");
Date t;
try {
t = ft.parse(input);
System.out.println(t);
} catch (Exception e) {
System.out.println("Unparseable using " + ft);
}
try {
long start = System.currentTimeMillis( );
String str= String.format("1次%d",start);
System.out.println(str);
System.out.println(new Date( ) + "\n");
Thread.sleep(5*60*10);
System.out.println(new Date( ) + "\n");
long end = System.currentTimeMillis( );
long diff = end - start;
System.out.println("Difference is : " + diff);
} catch (Exception e) {
System.out.println("Got an exception!");
}
Date date1=new Date();
SimpleDateFormat ft1=new SimpleDateFormat("yyyy-MM");
String s=ft1.format(date1);//解析成字符串
System.out.println("date时间类型自定义显示"+s);
try{
Date date2=ft1.parse(s);
System.out.printf("将符合某种形式的字符串转为date形式%tc",date2);
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
}
Java Date
最新推荐文章于 2024-08-01 23:01:26 发布