I make a ToDoItem in Single Page Application, using model Activity.cs instead of ToDoItem.cs.
Here my Activity.cs
namespace ToDoActivity.Models
{
public class Activity
{
public int Id { get; set; }
[Required]
[StringLength(50)]
public string Name { get; set; }
public string Description { get; set; }
public int ParentId { get; set; }
public int PersonInCharge { get; set; }
public System.DateTime DateStart { get; set; }
public Nullable<System.DateTime> DateEnd { get; set; }
public System.DateTime ModifiedDate { get; set; }
[Display(AutoGenerateField = false)]
public System.Guid? rowGuid { get; set; }
}
}
I can not type dd-mmm-yyyy during create a new activity or edit an activity.
I need to change date format to regular date format, during create a new acitivity and edit an activity. If possible using DatePicker for editing, and display format dd/mm/yyyy or other regular format.
Thank's for reply. But this in SPA of MVC, I've looked at knockoutjs.com, but it never has any kind of that date format. I really don't know that kind of date format is that. I got that date when I update regular date on my SQL database directly, and render
with the view I posted, the date format on the display become like that.
On database: 24/05/2012 00:00:00, on my view: /Date(1337878800000+0700)/
I do not familiar with that date. The problem is I have to enter the date during new entry or edit.
It is not practice to enter or edit this kind of date format by user.
<div class="container"> <div class="line number1 index0 alt2">// Create Json.Net formatter serializing DateTime using the ISO 8601 format</div> <div class="line number2 index1 alt1">JsonSerializerSettings
serializerSettings = new
JsonSerializerSettings();</div> <div class="line number3 index2 alt2">serializerSettings.Converters.Add(newIsoDateTimeConverter());</div> <div class="line number4 index3 alt1">GlobalConfiguration.Configuration.Formatters[0] =
newJsonNetFormatter(serializerSettings);</div> </div>
</div> </div>
When we ship, none of this will be needed as it should be the default which is much nicer. JSON.NET will be the default serializer AND Web API will use ISO 8601 on the wire as the default date format for JSON APIs.
QUOTE
I add the following code to Web.Config after following the the above reference:
JsonSerializerSettings serializerSettings = new JsonSerializerSettings(); // using Newtonsoft.Json;
serializerSettings.Converters.Add(new IsoDateTimeConverter()); // using Newtonsoft.Json.Converters;
GlobalConfiguration.Configuration.Formatters[0] = new JsonNetFormatter(serializerSettings); // using Thinktecture.Web.Http.Formatters;
I am going to get back here after I can solved the short date format
Jannen Siahaan
Indonesian Humanitarian Foundation
Marked as answer by jsiahaan on May 26, 2012 06:02 AM
Still, you may run into the problem of "This DataController does not support operation insert for entity jobject" when trying to do a form POST(eg.: create new Activity) using the JsonNetFormatter,
jsiahaan
Contributor
2302 Points
585 Posts
Change date format /Date(1337878800000+0700)/ to regular date format, example dd/mm/yyyy hh:mm:ss
May 25, 2012 02:51 AM|LINK
I make a ToDoItem in Single Page Application, using model Activity.cs instead of ToDoItem.cs.
Here my Activity.cs
namespace ToDoActivity.Models { public class Activity { public int Id { get; set; } [Required] [StringLength(50)] public string Name { get; set; } public string Description { get; set; } public int ParentId { get; set; } public int PersonInCharge { get; set; } public System.DateTime DateStart { get; set; } public Nullable<System.DateTime> DateEnd { get; set; } public System.DateTime ModifiedDate { get; set; } [Display(AutoGenerateField = false)] public System.Guid? rowGuid { get; set; } } }On _Grid.cshtml,
<h2>Activities (<span data-bind="text: activities().length"></span>)</h2> <table> <thead> <tr> <th>Id</th> <th>Name</th> <th>Description</th> <th>ParentId</th> <th>PersonInCharge</th> <th>DateStart</th> <th>DateEnd</th> <th>ModifiedDate</th> <th>rowGuid</th> </tr> </thead> <tbody data-bind="foreach: activities"> <tr data-bind="css: { added: IsAdded, updated: IsUpdated, deleted: IsDeleted, error: EntityError }"> <td data-bind="text: Id"></td> <td data-bind="text: Name"></td> <td data-bind="text: Description"></td> <td data-bind="text: ParentId"></td> <td data-bind="text: PersonInCharge"></td> <td data-bind="text: DateStart"></td> <td data-bind="text: DateEnd"></td> <td data-bind="text: ModifiedDate"></td> <td data-bind="text: rowGuid"></td> <td><a href="#" data-bind="click: $parent.openEditor">Edit</a></td> </tr> </tbody> </table> <p><a href="#" data-bind="click: createActivity">Create new</a></p> <button data-bind="click: saveAll">Save all</button> <button data-bind="click: revertAll">Revert all</button>Result in browser:
/Date(1337878800000+0700)/
I can not type dd-mmm-yyyy during create a new activity or edit an activity.
I need to change date format to regular date format, during create a new acitivity and edit an activity. If possible using DatePicker for editing, and display format dd/mm/yyyy or other regular format.
Please help
Indonesian Humanitarian Foundation
Bhavik Solu...
Member
746 Points
159 Posts
Re: Change date format /Date(1337878800000+0700)/ to regular date format, example dd/mm/yyyy hh:m...
May 25, 2012 10:00 AM|LINK
Hope it will help
i have done small function in my project for clinet side to get date
var value="/Date(1337878800000+0700)/"; if (value.substring(0, 6) == "/Date(") { var dt = new Date(parseInt(value.substring(6, value.length - 2))); var dtString = (dt.getMonth() + 1) + "/" + dt.getDate() + "/" + dt.getFullYear(); }jsiahaan
Contributor
2302 Points
585 Posts
Re: Change date format /Date(1337878800000+0700)/ to regular date format, example dd/mm/yyyy hh:m...
May 25, 2012 12:10 PM|LINK
Hi Bhavik,
Thank's for reply. But this in SPA of MVC, I've looked at knockoutjs.com, but it never has any kind of that date format. I really don't know that kind of date format is that. I got that date when I update regular date on my SQL database directly, and render with the view I posted, the date format on the display become like that.
On database: 24/05/2012 00:00:00, on my view: /Date(1337878800000+0700)/
I do not familiar with that date. The problem is I have to enter the date during new entry or edit.
It is not practice to enter or edit this kind of date format by user.
Again thanks for trying to help.
Indonesian Humanitarian Foundation
dboy8454
Member
8 Points
6 Posts
Re: Change date format /Date(1337878800000+0700)/ to regular date format, example dd/mm/yyyy hh:m...
May 25, 2012 12:40 PM|LINK
I have the same problem,
here is just an idea, in the MVVM ViewModel:
self.TimePropertyOriginal = ko.observable(); // TimePropertyOriginal == "/Date(1337878800000+0700)/"
self.TimePropertyComputed= ko.computed({ // TimePropertyComputed == "24/05/2012 00:00:00"write: function(){btw:in javascript, new Date(1337878800000).getTime() == 1337878800000 is true.BrockAllen
All-Star
27438 Points
4893 Posts
MVP
Re: Change date format /Date(1337878800000+0700)/ to regular date format, example dd/mm/yyyy hh:m...
May 25, 2012 01:33 PM|LINK
http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
kashifilyaz
Participant
1144 Points
198 Posts
Re: Change date format /Date(1337878800000+0700)/ to regular date format, example dd/mm/yyyy hh:m...
May 25, 2012 01:40 PM|LINK
Please change dateformat to your required format and then convert it to string.You can add one more property
in Activity class like
public string DateStartString { get; set; }jsiahaan
Contributor
2302 Points
585 Posts
Re: Change date format /Date(1337878800000+0700)/ to regular date format, example dd/mm/yyyy hh:m...
May 25, 2012 10:48 PM|LINK
Hi,
Thank you all for all replies, I have not success yet, I'm keeping trying BrockAllen has, also not success yet, I'm sure this is now about my knowledge still in a learning phase, I need more concentration to use this site http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx.
Again thank you all, I'll come here again success or not.
Indonesian Humanitarian Foundation
jsiahaan
Contributor
2302 Points
585 Posts
Re: Change date format /Date(1337878800000+0700)/ to regular date format, example dd/mm/yyyy hh:m...
May 26, 2012 06:01 AM|LINK
Hi all,
Now I have a progress. I can make date from /Date(1337878800000+0700)/ to 2012-05-25T00:00:00,
But I still looking for the good format remove T00:00:00 on short date format.
The solution based on http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx.
at part of comment of Raffi Krikorian @raffi:
QUOTE
We're going to do this by default in ASP.NET Web API when it releases. (We aren't doing this now in Beta) You can see how to swap out the serializer to JSON.NET on Henrik's blog. You can also check out the Thinktecture.Web.Http convenience methods that bundles some useful methods for ASP.NET Web API.
Today with the Beta, I just need to update my global.asax and swap out the JSON Formatter like this (see Henrik's blog for the full code):
<div> <div id="highlighter_575926" class="syntaxhighlighter js">// Create Json.Net formatter serializing DateTime using the ISO 8601 format</div> <div class="line number2 index1 alt1">JsonSerializerSettings serializerSettings =newJsonSerializerSettings();</div> <div class="line number3 index2 alt2">serializerSettings.Converters.Add(newIsoDateTimeConverter());</div> <div class="line number4 index3 alt1">GlobalConfiguration.Configuration.Formatters[0] =newJsonNetFormatter(serializerSettings);</div> </div>When we ship, none of this will be needed as it should be the default which is much nicer. JSON.NET will be the default serializer AND Web API will use ISO 8601 on the wire as the default date format for JSON APIs.
QUOTE
I add the following code to Web.Config after following the the above reference:
JsonSerializerSettings serializerSettings = new JsonSerializerSettings(); // using Newtonsoft.Json; serializerSettings.Converters.Add(new IsoDateTimeConverter()); // using Newtonsoft.Json.Converters; GlobalConfiguration.Configuration.Formatters[0] = new JsonNetFormatter(serializerSettings); // using Thinktecture.Web.Http.Formatters;I am going to get back here after I can solved the short date format
Indonesian Humanitarian Foundation
dboy8454
Member
8 Points
6 Posts
Re: Change date format /Date(1337878800000+0700)/ to regular date format, example dd/mm/yyyy hh:m...
May 26, 2012 06:12 AM|LINK
Still, you may run into the problem of "This DataController does not support operation insert for entity jobject" when trying to do a form POST(eg.: create new Activity) using the JsonNetFormatter,
Good luck.