Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
519 views
in Technique[技术] by (71.8m points)

javascript - Javascript将日期更改为(dd / mm / yyyy)的格式[重复](Javascript change date into format of (dd/mm/yyyy) [duplicate])

Possible Duplicate:(可能重复:)

How can I convert the following date format below (Mon Nov 19 13:29:40 2012)(我如何转换以下日期格式(Mon Nov 19 13:29:40 2012))

into:(成:)

dd/mm/yyyy(日/月/年)

<html>
    <head>
    <script type="text/javascript">
      function test(){
         var d = Date()
         alert(d)
      }
    </script>
    </head>

<body>
    <input onclick="test()" type="button" value="test" name="test">
</body>
</html>
  ask by user1451890 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Some JavaScript engines can parse that format directly, which makes the task pretty easy:(一些JavaScript引擎可以直接解析该格式,这使得任务非常简单:)

function convertDate(inputFormat) {
  function pad(s) { return (s < 10) ? '0' + s : s; }
  var d = new Date(inputFormat);
  return [pad(d.getDate()), pad(d.getMonth()+1), d.getFullYear()].join('/');
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...