date - Javascript remove time from datetime - Stack Overflow

I am using full calendar and using the date from the eventclick calEvent._start._i returns: 201

I am using full calendar and using the date from the eventclick

calEvent._start._i         returns: 2015-12-01 09:00:00

and I want to pare it to another date although it is this format

2015-12-01

I have used

var date = new Date(calendarDate);
date.setHours(0,0,0,0);

which returns an invalid date format

I have also used

var calDate = _longDateFormat(calendarDate, "dd-mm-yy");

which errored on the javascript

Nothing seems to work, including dateFormat.

Ideas?

I am using full calendar and using the date from the eventclick

calEvent._start._i         returns: 2015-12-01 09:00:00

and I want to pare it to another date although it is this format

2015-12-01

I have used

var date = new Date(calendarDate);
date.setHours(0,0,0,0);

which returns an invalid date format

I have also used

var calDate = _longDateFormat(calendarDate, "dd-mm-yy");

which errored on the javascript

Nothing seems to work, including dateFormat.

Ideas?

Share edited Aug 26, 2019 at 2:07 Dale K 27.5k15 gold badges58 silver badges83 bronze badges asked Dec 1, 2015 at 10:57 bananabreadbobbananabreadbob 4073 gold badges13 silver badges30 bronze badges 4
  • what do you want to pare? Two Dates ignoring the time? – Martin Schneider Commented Dec 1, 2015 at 11:05
  • Yes, at the moment becausae the times are different it doesn't work – bananabreadbob Commented Dec 1, 2015 at 11:10
  • 1 Try this stackoverflow./a/19054782/5089795 – Martin Schneider Commented Dec 1, 2015 at 11:15
  • if (requestedDate.sameDay(calendarDate)){ return true; } when running through firebug it doesn't do anything – bananabreadbob Commented Dec 1, 2015 at 11:35
Add a ment  | 

2 Answers 2

Reset to default 3

I was facing the same problem and I didn't want to use specific formatting options because I wanted the date to be displayed in the correct local format. I ended up using a simple regex replace, maybe this approach will help you as well:

new Date().toLocaleString().replace(/\s\d{2}:\d{2}:\d{2,4}$/, ''))

You could do something like this:

function checkWhetherCorrectDate(requestedDate, calendarDate) {
    var date1 = new Date(calendarDate.replace(/-/g,'/'));
    var date2 = new Date(requestedDate);
    date1.setHours(date2.getHours(), date2.getMinutes(), date2.getSeconds());
    return date1.getTime() === date2.getTime();
}


document.write(checkWhetherCorrectDate("2015-12-01", "2015-11-30 09:00:00") + '<br />')
document.write(checkWhetherCorrectDate("2015-12-01", "2015-12-01 09:00:00") + '<br />')

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

相关推荐

  • date - Javascript remove time from datetime - Stack Overflow

    I am using full calendar and using the date from the eventclick calEvent._start._i returns: 201

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信