I have a problem in converting date in javascript . i try this snippet:
$(document).ready(function () {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
theme: true,
header: {left: 'prev,next today',center: 'title',right: 'month,agendaWeek,agendaDay'},
editable: true,
events: [
{
title: 'Birthday Party',
start: new Date(y, m, d+1, 19, 0),
end: new Date(y, m, d+1, 22, 30),
allDay: false
}
]
});
});
and it works, but if i change it to:
$(document).ready(function () {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
theme: true,
header: {left: 'prev,next today',center: 'title',right: 'month,agendaWeek,agendaDay'},
editable: true,
events: [
@foreach (var m in Model.Get_List_Tache())
{
@:{ title: "Tache_description", start: new Date(@m.Begin_date.Year +"," + @m.Begin_date.Month +","+ @m.Begin_date.Day ) , end: new Date( @m.End_date.Year +"," [email protected]_date.Month +"," + @m.End_date.Day ) }
}
]
});
});
There is a syntaxic error in the format of date.
So what is the reason of this error? How can i fix it?
The DateTime. ParseExact(String, String, IFormatProvider) method parses the string representation of a date, which must be in the format defined by the format parameter.
You can use the methods like Convert. ToDateTime(String), DateTime. Parse() and DateTime. ParseExact() methods for converting a string-based date to a System.
DateTimeOffset contains information about the timezone you are dealing with, which makes all the difference in THE WORLD! The only difference is that it stores only the UTC offset for the particular instant in time that a DateTime represents.
You can use this solution
start: new Date(@m.Begin_date.ToString("yyyy,MM-1,dd"))
I'm still with FosterZ, but you should also get rid of the +
as well.
So instead of
start: new Date(@m.Begin_date.Year +"," + @m.Begin_date.Month +","+ @m.Begin_date.Day ) ,
try
start: new Date(@m.Begin_date.Year , @m.Begin_date.Month , @m.Begin_date.Day ) ,
If that still doesn't work, then view the source of the page, and see what is being put into the Javascript there. It's most likely not what you're expecting it to be. If you can't figure it out, add that to your question and we can take a look at it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With