Sign up ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using the javascript object model to get a date field back and display it on a page e.g. oListItem.get_item("MyTestDate")

This displays on the page by default as: Thu Jul 25 09:30:07 PDT 2013

I want to display it as: 25 Jul 2013, 09:30

How do i format a date when using the JSOM

share|improve this question

2 Answers 2

ASP.NET AJAX (which is a part of SharePoint - MicrosoftAjax.js) extends the JavaScript Date object with a formatting function that closely mimics the DateTime.ToString method

So, in your case the format string should be as follows: dd MMM yyyy, hh:ss

var modified = item.get_item("Modified");
var fmtModified = modified.format('dd MMM yyyy, hh:ss');

For a full list of formatting string parameters, see the Standard DateTime Format Strings and Custom DateTime Format Strings reference pages on MSDN

share|improve this answer
    
Your suggestion does not work in javascript object model on IE 8. – Mario Pereira Aug 19 '13 at 14:00
    
It works on my computer, but what about specifying the culture? – Steve B Jun 11 '14 at 13:41

I like to use Moment.js

It is easy to learn and very small.

share|improve this answer
1  
I was about to suggest this myself. Moment.js is an excellent library. I use it in all of my SharePoint projects that have custom front-end work. – Robert Kaucher Aug 19 '13 at 15:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.