Date d = new Date();
String date = d.toLocaleString(); //获取当前日期,然后你可以自己对这个字符串进行处理。或者用d.getDate();等方法,单独取它的日期等等。
Timestamp time = new Timestamp(System.currentTimeMillis());
System.out.println(time.toString());
import java.lang.System;
import java.util.Date;
public class Date{
public static void main(String args[]){
Date today=new Date();
System.out.println("Today's date(Locale) is:"
+today.toLocaleString());
}
}
Calendar cal=Calendar.getInstance();
Date now=new Date();
cal.setTime(now);
import java.util.*;
import java.text.*;
public class DateDemo{
public static void main(String[] args){
SimpleDateFormat dateFormatter =new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
GregorianCalendar gc=new GregorianCalendar();
System.out.println(dateFormatter.format(gc.getTime()));
}
}