English 中文(简体)
有一个图书馆将1天改为86 400 000
原标题:is there a library that convert 1 day into 86400000

页: 1 Im从一个可读体向一些小片

类似:

var key = { s: 1000, m:1000*60, h:1000*60*60, d: 1000*60*60*24, ... },
    m = str.match((d+) (w)),
    result = m[1] * (key[m[2]] || 1); 
最佳回答

你们的法典应该很好地发挥作用。 我采纳了这一基本想法,并共同承担一个可以合并单位的更灵活的职能。 这份文件extremely放宽了它接受的内容,但是如果你想要的话,你可以使其更加严格。

(function() {
    var units = {
        ms: 1/1000,

        m: 60,
        min: 60, mins: 60,
        minute: 60, minutes: 60,

        h: 60*60,
        hr: 60*60, hrs: 60*60,
        hour: 60*60, hours: 60*60,

        d: 60*60*24,
        day: 60*60*24, days: 60*60*24,
    };

    Date.parseInterval = function(interval) {
        var seconds = 0;
        interval.replace(/(d+(?:.d*)?)s*([a-z]+)?/ig, function($0, number, unit) {
            if (unit) {
                number *= units[unit.toLowerCase()] || 1;
            }
            seconds += +number;
        });
        return seconds * 1000;
    };
})();

console.log(Date.parseInterval( 1 day ) === 86400000);
console.log(Date.parseInterval( 20 min ) === 1200000);
console.log(Date.parseInterval( 1 day, 3 hours, and 22.5 seconds ) === 97222500);
问题回答
strToMs = function(str) {
    var multiplier = {
        ms: 1, mil: 1, s:1000, sec: 1000, min: 1000*60,
        hr: 1000*60*60, hrs: 1000*60*60, hou: 1000*60*60,
        d: 1000*60*60*24, day: 1000*60*60*24, mon: 1000*60*60*24*30,
        y: 1000*60*60*24*386.25, yea: 1000*60*60*24*386.25
    },
    num = str.match(/d+/), units = str.match(/[a-z]{1,3}/i)
    return num * (multiplier[units] || 1);
}

DEMO

装在日期的物体可以处理许多 st子。 否则,例如。 可能是有益的

过去,我利用 查询日期:js图书馆取得了成功。

似乎支持诸如<代码>now + 20 min等划线体,因此,最糟糕的是,您可细分<代码>now/code>(或任何固定日期tn t似乎支持这一点),然后打电话getMilliseconds()。





相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签