/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package testdate;
import java.util.Date;
/**
*
* @author sd01
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Date date = new Date();
System.out.println(date.toString());//获取当前时间
}
}
使用SimpleDateFormat格式化日期:它准许用户自定义格式化日期操作;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package testdate;
import java.util.*;
import java.text.*;
import javax.print.attribute.Size2DSyntax;
/**
*
* @author sd01
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Date date = new Date();
System.out.println(date.toString());//获取当前时间
SimpleDateFormat ft = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz" );//E表示缩写的星期几,单引号表示文字定界符,小写a表示上午还是下午,z表示时区;
}
}