How do I convert DateTime to another format?

送分小仙女□ 提交于 2019-12-14 03:25:10

问题


From a weather feed I'm getting the data for dates in the form of 2012-05-17.

How do I convert that to Thursday May 17th form?


回答1:


  1. Parse the string into a JavaScript Date object.
  2. Format the Date object however you like.

See also: Why does Date.parse give incorrect results? and How to format a JavaScript date questions.




回答2:


How about this:

var originalDateTime = '2012-05-17',
splitedDatetime = originalDateTime.split('0'),
date = new Date(),
date.setFullYear(splitedDatetime[0],splitedDatetime[1]-1,splitedDatetime[2]),
formatedDateString = date.toLocaleFormat("%A %B %d");


来源:https://stackoverflow.com/questions/10657357/how-do-i-convert-datetime-to-another-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!