jquery trim leading zeros from date of format 01/02/2010

你说的曾经没有我的故事 提交于 2019-12-06 05:42:48

For a simple string operation, a RegEx can be used:

date = date.replace(/\b0(?=\d)/g, '')
Jason McCreary

If it is indeed a date object format it.

Quick example (See it in action):

var today = new Date();
var today_string = (today.getMonth() + 1) + '/' + today.getDate() + '/' + today.getFullYear();
alert(today_string);

Either way, this is not a good use of regular expressions.

Convert to a Date object first. http://www.w3schools.com/jsref/jsref_obj_date.asp

Javascript doesn't have built-in formatting functions for dates, but there are a lot of simple libraries that serve this need. Personal favorite: http://blog.stevenlevithan.com/archives/date-time-format

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