代码拉取完成,页面将自动刷新
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* @author LiuYan
* @date 2021/11/15 8:50
*/
public class Part09 {
/**
* Date里面的一些方法过时了
*/
public static void main(String[] args) throws ParseException {
Calendar now = Calendar.getInstance();
// 获取年月日时分秒
int year = now.get(Calendar.YEAR);
int moth = now.get(Calendar.MONTH);// 获取当前月份索引(0-11)
int day = now.get(Calendar.DAY_OF_MONTH);
int hour = now.get(Calendar.HOUR);
int minute = now.get(Calendar.MINUTE);
int second = now.get(Calendar.SECOND);
System.out.println(year);
System.out.println(moth);
System.out.println(day);
System.out.println(hour);
System.out.println(minute);
System.out.println(second);
// 设置时间
now.set(2022, 12, 12, 12, 12, 12);
now.set(Calendar.YEAR,2222);
// Date---->Calendar
now.setTime(new Date());
// Calendar---->Date
Date time = now.getTime();
System.out.println(time);
// Calendar添加字段(添加两个月)
now.add(Calendar.MONTH,2);
// String---->Date
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy--MM-dd HH:mm:ss");
String str="2021-12-12 00:00:00";
simpleDateFormat.parse(str);
// Date---->String
Date date=new Date();
String format = simpleDateFormat.format(date);
System.out.println(format);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。