使用js获取当前时间戳,并尝试将当前日期,时间,秒,毫秒附加到单个字符串中
例如:2912019121216174
29-1-2019-这表示当前日期。 12:12:16:174-这代表当前时间,秒及其毫秒。
答案 0 :(得分:2)
好啦!几分钟之内,我得到了我所没有的例外结果。
HTML
<p id="demo"></p>
JavaScript
var currentDate = new Date();
var date = currentDate.getDate();
var month = currentDate.getMonth(); //Be careful! January is 0 not 1
var months = (month+1);
var year = currentDate.getFullYear();
var hours = currentDate.getHours();
var minutes = currentDate.getMinutes();
var seconds = currentDate.getSeconds();
var milliseconds = currentDate.getMilliseconds();
var dmy = (""+date+months+year+hours+minutes+seconds+milliseconds);
document.getElementById("demo").innerHTML = dmy;