3 回答
TA贡献1829条经验 获得超13个赞
你的意思是像
toLocaleString、 toLocaleDateString和/或toLocaleTimeString
const d = new Date(1585740129850);
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric'};
console.log(d.toLocaleString('de-DE',options),d.toLocaleTimeString('de-DE'))
console.log(
d.toLocaleDateString(),
d.toLocaleTimeString('en-US')
)
TA贡献1735条经验 获得超5个赞
我已将其发布在这里: https: //codepen.io/mxnelles/pen/PoqLyPV
function gd(timestamp) {
var date = new Date(timestamp * 1000);
var hours = date.getHours();
var minutes = "0" + date.getMinutes();
var seconds = "0" + date.getSeconds();
var formattedTime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
return formattedTime;
}
$(function() {
$("#calc").click(function() {
$("#result").text(gd($("#raw").val()));
})
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div style="padding:30px">
<input type="text" value="1585740248" id="raw">
<button id="calc">Convert Time</button>
<div id="result"></div>
</div>
TA贡献1820条经验 获得超2个赞
转变:
var utcSeconds = 1585740122250;
var somedate = new Date(utcSeconds);
$('#Window').html(somedate.getUTCSeconds()); // format here
格式:
您可以查看:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
var somedate = new Date();
// toLocaleDateString() without arguments depends on the implementation,
// the default locale, and the default time zone
console.log(somedate.toLocaleDateString());
// → "12/11/2012" if run in en-US locale with time zone America/Los_Angeles
- 3 回答
- 0 关注
- 123 浏览
添加回答
举报