如何在存储和从数据库检索时将datetime-local转换为datetime

vin*_*ini 5 javascript jquery datetime

我正在努力使这个可能如何转换datetime-local我在jquery mobile中使用并将数据存储为datetime,因为我的字段是数据库中的datetime

'<input type="datetime-local"' + demodata + ' />';
Run Code Online (Sandbox Code Playgroud)

我正在使用jquery mobile并遇到重大问题

        if($(this).attr('type')==='datetime-local')
    {
              var $datevalue  =$(this).val();
                a[$(this).attr('name')] = $datevalue.toString(); //Have to convert to datetime instead
    }
Run Code Online (Sandbox Code Playgroud)

我的datetime-local值采用以下格式: 2014-07-18T12:12

Mak*_*nko 11

有一些moment.js库可以进行大量的日期时间处理,包括时区,日期格式等.它正确处理DST时间.

此代码根据用户的时区设置将本地时间转换为UTC(在我的情况下为Australian EDT(UTC +1100)):

// convert local time to UTC
moment(new Date(2014, 0, 1, 0, 0, 0)).utc().format() 
// returns "2013-12-31T13:00:00+00:00"

// convert UTC to local time
moment.utc("2013-07-31T05:05").local().format()
// returns "2013-07-31T15:05:00+10:00"
Run Code Online (Sandbox Code Playgroud)