datetime to timestamp javascript - Stack Overflow

i have this time format : DateTime(2015, 5, 11, 12, 0, 0)i would like to know if i can convert it into

i have this time format :

DateTime(2015, 5, 11, 12, 0, 0)

i would like to know if i can convert it into a time stamp.

i have made this convert function from ISO 8601 to Timestamp and i would like to know if i can adapt it to this time format :

var myDate = new Date("2017-07-31T15:30:00+0000");
var offset = myDate.getTimezoneOffset() * 60 * 1000;

var withOffset = myDate.getTime();
var withoutOffset = withOffset - offset;

console.log(myDate.getTimezoneOffset()*60 * 1000)
console.log('with Offset  ' + withOffset);
console.log('without Offset (timeStamp of your timezone) ' +withoutOffset);

i have this time format :

DateTime(2015, 5, 11, 12, 0, 0)

i would like to know if i can convert it into a time stamp.

i have made this convert function from ISO 8601 to Timestamp and i would like to know if i can adapt it to this time format :

var myDate = new Date("2017-07-31T15:30:00+0000");
var offset = myDate.getTimezoneOffset() * 60 * 1000;

var withOffset = myDate.getTime();
var withoutOffset = withOffset - offset;

console.log(myDate.getTimezoneOffset()*60 * 1000)
console.log('with Offset  ' + withOffset);
console.log('without Offset (timeStamp of your timezone) ' +withoutOffset);

Share edited Jul 27, 2017 at 8:38 steliosbl 8,9214 gold badges32 silver badges57 bronze badges asked Jul 27, 2017 at 8:35 moonshinemoonshine 8692 gold badges12 silver badges25 bronze badges 2
  • see this link coderwall./p/rbfl6g/… – Ghassen Rjab Commented Jul 27, 2017 at 8:37
  • Also have a look at moment.js: momentjs. – Sventies Commented Jul 27, 2017 at 8:41
Add a ment  | 

3 Answers 3

Reset to default 10

did you try

Date.parse(your date here)/1000

Date.parse(new Date(2015, 5, 11, 12, 0, 0))/1000

you can use the library momentjs to convert it.

Here you are assigning an instance of momentjs to CurrentDate:

var CurrentDate = moment();

Here just a string, the result from default formatting of a momentjs instance:

var CurrentDate = moment().format();

And here the number of seconds since january of... well, unix timestamp:

var CurrentDate = moment().unix();

momentjs guide

Parsing dates is a pain in JavaScript as there's no extensive native support. However you could do something like the following by relying on the Date(year, month, day [, hour, minute, second, millisecond]) constructor signature of the Date object.

var dateString = '17-09-2013 10:08',
dateTimeParts = dateString.split(' '),
timeParts = dateTimeParts[1].split(':'),
dateParts = dateTimeParts[0].split('-'),
date;

date = new Date(dateParts[2], parseInt(dateParts[1], 10) - 1, dateParts[0], timeParts[0], timeParts[1]);

console.log(date.getTime()); //1379426880000
console.log(date); //Tue Sep 17 2013 10:08:00 GMT-0400

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743687581a4490406.html

相关推荐

  • datetime to timestamp javascript - Stack Overflow

    i have this time format : DateTime(2015, 5, 11, 12, 0, 0)i would like to know if i can convert it into

    3天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信