一. 获取当前系统时间和日期并格式化输出:
import java.util.Date;
import java.text.SimpleDateFormat;
public class NowString
{
public static void main(String[] args)
{
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
}
}
二.
Calendar c = Calendar.getInstance();//可以对每个时间域单独修改
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int date = c.get(Calendar.DATE);
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
int second = c.get(Calendar.SECOND);
int week=c.get(Calendar.DAY_OF_WEEK);
System.out.println(year + "/" + month + "/" + date + " " +hour + ":" +minute + ":" + second);
|
|