简体   繁体   English

Pickadate:将日期转换为Unix时间戳

[英]Pickadate: Convert date to unix timestamp

I have read the API located here: http://amsul.ca/pickadate.js/api/ 我已经阅读了位于此处的API: http : //amsul.ca/pickadate.js/api/

but couldn't find a way to convert the date output by the picker to a unix timestamp integer. 但找不到将选择器输出的日期转换为unix时间戳整数的方法。 Has anyone had any luck with it? 有人有运气吗?

you can use the 'set' event 您可以使用“设置”事件

picker.on({
  set: function(thingSet) {
    if (thingSet.select) {
      console.log(thingSet.select);
    }
  }
})

see the docs and see this codepen 看到文档 ,看到这个codepen

You can use the JavaScript Date.parse() method to convert the date string returned by onSet to the Unix epoch time in milliseconds. 您可以使用JavaScript Date.parse()方法将onSet返回的日期字符串转换为Unix纪元时间(以毫秒为单位)。

// date selector
var my_date = $('#my_date').pickadate({
    // onSet fires each time the date is changed
    onSet: function(context) {
        // only proceed if the returned object
        // has the select key
        if(context.select){
            // JavaScript Date.parse() automatically parses 
            // the date string into Unix epoch time in milliseconds
            var unix_timestamp = Date.parse(context.select);
            // log to console
            console.log(unix_timestamp);
        }
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM