怎样获取年月日,星期,工作日,休息日和节假日
发布于 6 年前 作者 jun67 2393 次浏览 来自 问答
  • 需求的场景描述(希望解决的问题)
  • 希望提供的能力

点击获取

1 回复

1.   //获取当前时间

function getCurrentMonthFirst() {

  var date = new Date();

  var todate = date.getFullYear() + “-” + ((date.getMonth() + 1) < 10 ? (“0” + (date.getMonth() + 1)) : date.getMonth()+1) + “-” + (date.getDate() < 10 ? (“0” + date.getDate()) : date.getDate());

  return todate;

}

2./**

   * 传入时间后几天

   * param:传入时间:dates:“2018-04-02”,later:往后多少天

   */

function dateLater(dates, later) {

  let dateObj = {};

  let show_day = new Array(‘周日’, ‘周一’, ‘周二’, ‘周三’, ‘周四’, ‘周五’, ‘周六’);

  let date = new Date(dates);

  date.setDate(date.getDate() + later);

  let day = date.getDay();

  dateObj.year = date.getFullYear();

  dateObj.month = ((date.getMonth() + 1) < 10 ? (“0” + (date.getMonth() + 1)) : date.getMonth()+1);

  dateObj.day = (date.getDate() < 10 ? (“0” + date.getDate()) : date.getDate());

  dateObj.week = show_day[day];

  return dateObj;

}

3.获取指定日期的节假日信息

1、接口地址:http://api.goseek.cn/Tools/holiday?date=数字日期,支持https协议。 
2、返回数据:工作日对应结果为 0, 休息日对应结果为 1, 节假日对应的结果为 2 
3、节假日数据说明:本接口包含2017年起的中国法定节假日数据,数据来源国务院发布的公告,每年更新1次,确保数据最新 
4、示例: 
http://api.goseek.cn/Tools/holiday?date=20170528 

转链接https://blog.csdn.net/a9925/article/details/80743374

回到顶部