-2

Not sure if this is the correct thread to post this type of question. I am calling a service which returns the date, but the format is quite weird. I couldn't figure out.

The format is : "/Date(1430953200000+0100)/"

and I want to convert this into dd month year format(ex 22 Feb 1991).

Any way to achieve this in javascript.

rampuriyaaa
  • 4,926
  • 10
  • 34
  • 41

3 Answers3

-1
var time = new Date().getTime();
var date = new Date(time);
alert(date.toString()); // Wed Jan 12 2011 12:42:46 GMT-0800 (PST)

From:
Converting milliseconds to a date (jQuery/JS)

Community
  • 1
  • 1
Jacob
  • 3,580
  • 22
  • 82
  • 146
  • 2
    IMO if you post exact code from another answer (even with proper reference) then...it's easier to close **this** as duplicate... – Adriano Repetti May 15 '14 at 11:22
-2

try this

mydate = new Date(1430953200000+0100)

then you can do whateveryou want with the js date format

Fiddle: http://jsfiddle.net/SLhQL/

Jacob
  • 3,580
  • 22
  • 82
  • 146
BFigueiredo
  • 176
  • 1
  • 7
-3

I'm pretty sure that this is the date in milliseconds.

I had the same problem a while ago and solved it using the following code. However, I wanted the MMM/DD/YYYY format, so you'll have to change the string a bit.

function convertDate(date) {
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
              'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

return months[date.getUTCMonth()] + ' ' + date.getUTCDate() + ' ' + date.getUTCFullYear();
}

console.log(convertDate(new Date(1430953200000));
daZza
  • 1,669
  • 1
  • 29
  • 51
  • Right but you're ignoring time zone offset. It may be an issue if offset (from server) isn't always 1 hour. – Adriano Repetti May 15 '14 at 11:32
  • He doesn't want to have a `hh:mm:ss format`, so it should be fine I guess? I also doubt that the location of his server will suddenly change timezones. – daZza May 15 '14 at 11:39
  • Offset is in hours so date may change. Server won't walk away to another country but we don't know how that date must be presented. For example, here on SO, server may return such date and each one of us will see date expressed in his own time zone (in this case you can't simply ignore it). – Adriano Repetti May 15 '14 at 11:47
  • Just out of curiosity, why are legit and working answers downvoted? – daZza May 20 '14 at 13:05
  • @daZza, even if the time part is not needed, you can report a wrong date if the offset is, let's say 1 hour and the user accessed the site after 23:00 he could see the date for the next day. Timezone issues must never be underestimated. Moreover, if the client (javascript) code creates additional date objects in the user's browser to later submit them on the server (maybe via date-picker widget), those will use the client's timezone. One should know how to work these around. – Ivaylo Slavov May 21 '14 at 06:52