0

こんにちは、私は単純な 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のようであるかどうかも確認します

4

2 に答える 2

2

正規表現は、この仕事に適したツールではありません。

、 などのDate()メソッドを使用して、日付を再フォーマットする必要があります。getDate()getFullYear()

于 2013-02-25T14:59:02.200 に答える
0

小数点以下の桁数は次のとおりです。

var x = twoDecimalPlace('1904686.92600000');
alert(x);
function twoDecimalPlace(decimal){
    var result = Number(decimal).toFixed(2);
    return(result);
 }

http://jsfiddle.net/6etNB/

于 2013-02-25T16:08:25.753 に答える