秒杀案例需求分析

代码:
package com.itheima.Time;import javax.xml.crypto.Data;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;public class Test {public static void main(String[] args) throws ParseException {String start="2023年11月11日 0:0:0";String end="2023年11月11日 0:10:0";String xj="2023年11月11日 0:01:18";String xp="2023年11月11日 0:10:57";SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");Date startDt = sdf.parse(start);Date endDt = sdf.parse(end);Date xjDt = sdf.parse(xj);Date xpDt = sdf.parse(xp);long startTime = startDt.getTime();long endTime = endDt.getTime();long xjTime = xjDt.getTime();long xpTime = xpDt.getTime();if (xjTime >= startTime && xjTime <= endTime) {System.out.println("小贾秒杀成功");}else{System.out.println("小贾秒杀失败");}if (xpTime >= startTime && xpTime <= endTime) {System.out.println("小皮秒杀成功");}else{System.out.println("小皮秒杀失败");}}
}

为什么学Calendar

注意事项及Calendar常用方法

代码:
package com.itheima.Time;import java.util.Calendar;
import java.util.Date;public class CalendarTest {public static void main(String[] args) {Calendar now = Calendar.getInstance();System.out.println(now);int year = now.get(Calendar.YEAR);System.out.println(year);int month = now.get(Calendar.MONTH);System.out.println(month);Date date = now.getTime();System.out.println(date);now.set(Calendar.MONTH,9);System.out.println(now.get(Calendar.MONTH));now.add(Calendar.MONTH, 1);System.out.println(now.get(Calendar.MONTH));now.add(Calendar.MONTH,-1);System.out.println(now.get(Calendar.MONTH));}
}
