用Javascript排除星期日和星期六

时间:2019-04-26 13:19:14

标签: javascript date

我的js项目运行正常,但我需要排除周六和周日,甚至是假期。能否请您查看我的代码以了解如何实现此目标。

<p>Meet me at <span id="thedate"></span></p>

<script>
var m_names = ["January", "February", "March",
    "April", "May", "June", "July", "August", "September",
    "October", "November", "December"
];

var d_names = ["Sunday", "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday"
];

var myDate = new Date();
myDate.setDate(myDate.getDate() + 7);
var curr_date = myDate.getDate();
var curr_month = myDate.getMonth();
var curr_day = myDate.getDay();

document.getElementById("thedate").innerHTML = (d_names[curr_day] 
    + "," + m_names[curr_month] + " " + curr_date);
</script>

1 个答案:

答案 0 :(得分:0)

您可以轻松地找出日期是否在星期一至星期五之间:

func locationManagerConfiguration(){
    location.requestAlwaysAuthorization()
    location.requestWhenInUseAuthorization()
    if CLLocationManager.locationServicesEnabled(){
        location.delegate = self
        location.desiredAccuracy = kCLLocationAccuracyBest
        location.startUpdatingLocation()
    }
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    // TODO: Check the array is not empty
    let sourceCoordinates = locations[0]
    let sourcePlacemark = MKPlacemark(coordinate: sourceCoordinates!)
}

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
    print("Location error: \(error)")
}