如何将当前日期转换为数字格式?

时间:2015-11-20 05:01:50

标签: javascript jquery date datetime

我正在接受这样的新约会:

            AVPlayer *player = [AVPlayer playerWithURL: [[NSBundle mainBundle] URLForResource:@"IMG_8481" withExtension:@"MOV"]];
            AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer: player];
            [self.layer addSublayer: playerLayer];
            [player play];

我的上述方法返回日期格式,如" day"数组和年份的月份名称。

但是后端人员需要这样的日期格式:

getCalender: function () {

            var monthNames = [
                "January", "February", "March", 
                "April", "May", "June", "July",  
                "August", "September", "October",
                "November", "December"
            ];

            var date = new Date();
            var day = date.getDate();
            var monthIndex = date.getMonth();
            var year = date.getFullYear();

            return (day + '-' + monthNames[monthIndex] + '-' + year);

        },

如何转换日期格式以匹配此内容? 有人帮帮我吗?

3 个答案:

答案 0 :(得分:3)

我试过这个,它对我来说很好用:

var date1 = new Date();
var n = date1.getTimezoneOffset();

console.log( '/Date(' + (+date1) + n +')/' );

谢谢大家!

答案 1 :(得分:0)

尝试在jquery中使用getTime(),如下所示 -

 RewriteEngine On
 RewriteCond %{REQUEST_URI} ^/system.*
 RewriteRule ^(.*)$ index.php?/$1 [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.+)$ index.php?/$1 [L]

答案 2 :(得分:0)

您可以尝试这样:

var dt = new Date(myDate);
var newDate = new Date(Date.UTC(dt.getFullYear(), dt.getMonth(), dt.getDate(), dt.getHours(), dt.getMinutes(), dt.getSeconds(), dt.getMilliseconds()));
return '/Date(' + newDate.getTime() + ')/';

<强> DEMO

如果您想添加偏移时间,请执行

var dt = new Date();
var newDate = new Date(Date.UTC(dt.getFullYear(), dt.getMonth(), dt.getDate(), dt.getHours(), dt.getMinutes(), dt.getSeconds(), dt.getMilliseconds()));
return '/Date(' + newDate.getTime()  +  newDate.getTimezoneOffset() +')/' ;

<强> DEMO