H_MZ 2017-07-22 06:41 采纳率: 0%
浏览 70

javascript获取时间范围

I have an ajax request that returns a date and time. my ajax output is 7/22/2017, 3:35:51 PM, How can I get the time and have a condition between 9:00am to 5:00pm. Thank you in advance.

$.ajax({
          async: false,
          type: "POST",
          url: apicall,
          success: function (response) {
           console.log(response);
               var offsets = response.dstOffset * 1000 + response.rawOffset * 1000 // get DST and time zone offsets in milliseconds
            var localdate = new Date(timestamp * 1000 + offsets) // Date object containing current time of Tokyo (timestamp + dstOffset + rawOffset
              console.log(localdate.toLocaleString()) // Display current Tokyo date and time

          }

    }); 
  • 写回答

2条回答 默认 最新

  • weixin_33714884 2017-07-22 06:51
    关注

    Using momentjs would be easier, in my opinion

    getting the current time is as simple as moment()

    to check if it's between a time range: [http://momentjs.com/docs/#/query/is-between/]

    评论

报告相同问题?