3

I get date from Web Service have format date like "2013-02-06T10:40:56.027" how to convert it to "2/6/2013 2:40 AM".

enter image description here

Web Service I get from SocialDataService of Sharepoint 2010

I try moment javascript:

var date = moment(lastModifiedTime);

var result = date.format("MM/DD/YYYY hh:mm A");

but result not correct hour: 02/06/2013 10:40 AM

I expected result: 02/06/2013 2:40 AM

7
  • 2
    The original time does not have timezone information. Seems you have to calculate your local time with your timezone (or user's timezone) ?
    – Raptor
    Feb 7, 2013 at 2:44
  • do you have formula to calculate for US timezone?
    – Garu Jwon
    Feb 7, 2013 at 2:55
  • 2
    i think @ShivanRaptor is saying the service output should contain the timezone info, otherwise it is impossible to know the absolute time. Feb 7, 2013 at 2:57
  • 1
    @GraceShao Yes, The result of Web Service don't contain the timezone info.
    – Garu Jwon
    Feb 7, 2013 at 3:00
  • Nobody can have solution for that? It really impossible?
    – Garu Jwon
    Feb 7, 2013 at 3:09

2 Answers 2

3

if you can assume your service returns UTC time, you could try something like:

moment.utc(result_from_service).local()

for more details: http://momentjs.com/docs/#/manipulating/utc/

0
0
//Manually add time zone to the date string
var date = moment(lastModifiedTime + "+15:00");
var result = date.format("MM/DD/YYYY hh:mm A");
1
  • This would be a stronger answer if you explain it in addition to providing code.
    – Eric J.
    Feb 7, 2013 at 3:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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