質問

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.

役に立ちましたか?

解決 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));

他のヒント

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)

try this

mydate = new Date(1430953200000+0100)

then you can do whateveryou want with the js date format

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top