大家好,我有一个简单的 javascript 问题,希望有人能帮我解决这个问题
function changeDate(){
var date = '2/1/2013 12:00:00 AM';
var newDate = date.replace^(?ni:(?=\d)((?'year'((1[6-9])|([2-9]\d))\d\d)(?'sep'[/.-])(?'month'0?[1-9]|1[012])\2(?'day'((?<!(\2((0?[2469])|11)\2))31)|(?<!\2(0?2)\2)(29|30)|((?<=((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(16|[2468][048]|[3579][26])00)\2\3\2)29)|((0?[1-9])|(1\d)|(2[0-8])))(?:(?=\x20\d)\x20|$))?((?<time>((0?[1-9]|1[012])(:[0-5]\d){0,2}(\x20[AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2}))?)$
alert(newDate); // i need this to alert just '02/01/2013'
}
function twoDecimalPlace{
var decimal = '1904686.92000000';
//do something;
alert(decimal) // this should alert 1904686.92
}
所以基本上我需要截断时间并缩短日期。对于小数位,我需要将其缩短到小数点后 2 位,并查看它是否类似于 0.988,如果尾随数字大于 5,则应该将 0.99 四舍五入到下一个最大值