2

I am using bootstrap datetimepicker have to get the datetime and add days to it

var get_date_time =  Friday, October 23rd 2015, 12:00:00 am

format get_date_time to oct 25 2015 12:00:00 am how to format

How to format this to

var d = new Date('oct 25 2015 12:00:00 am');
d.setDate(d.getDate() + 2)
alert(d);

output should be example

Tuesday, October 27th 2015, 12:00:00 am

How to achieve this?

markatte team
  • 217
  • 1
  • 2
  • 11

2 Answers2

0

You need to do the following...

Get your date var d = new Date('Oct 25 2015 12:00:00 am').

Then use d.getTime() to get total time in milliseconds. Then for each day you wish to add, add 3600000 to it. Then create a new date from that var newDate = new Date(1445758146777).

var d = new Date('Oct 25 2015 12:00:00 am');
var milisecs = d.getTime();
var oneDay = 3600000;

// Add one day to the date...

milisecs += oneDay;
var newDate = new Date(milisecs)

Then format it accordingly :-)

An0nC0d3r
  • 1,265
  • 12
  • 29
0

I have used moment.js http: //momentjs.com/ to convert particular format

 var get_date_time =  Friday, October 23rd 2015, 12:00:00 am

using moment js i have formatted to date like the below

alert(moment(get_date_from,'dddd, MMMM Do YYYY, h:mm:ss a').format("MMM DD YYYY h:mm:ss a"));

then i have followed like this to add number of days calculation

   var date1 = deal_from_date.setDate(deal_from_date.getDate() + 2); 
markatte team
  • 217
  • 1
  • 2
  • 11