通过Calendar类判断是否是周末及是否在指定时间

时间:2022-10-04 16:17:56
package time;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;

public class Weekday {
	public static void main(String[] args) {
		//long time=System.currentTimeMillis();
		Date date=new Date();
		long time=date.getTime();
		Timestamp ts=new Timestamp(time);
		System.out.println(ts);
		int zone=ts.getHours();
		System.out.println(zone);
		if(zone>=8&&zone<=18){
			System.out.println("xxxx");
		}else{
			System.out.println("oooo");
		}
		Calendar cal=Calendar.getInstance();
		cal.setTime(date);
		if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY||cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
			System.out.println("oooo");
		}else{
			System.out.println("xxxx");
		}
	}

}