I dont wanna manual convertion, i have the jquery datepicker v.1.12.1 if i select the date from datepicker it will automatically convert timestamp format. i want a date format in timestamp like 28/09/2019 3:40 GMT-0400 this format to 1569668513 this format.
你能帮我吗?
var dateString = '#referdate',
dateTimeParts = dateString.split(' '),
timeParts = dateTimeParts[1].split(':'),
dateParts = dateTimeParts[0].split('/'),
date;
date = new Date(dateParts[2], parseInt(dateParts[1], 10) - 1, dateParts[0], timeParts[0], timeParts[1]);
console.log(date.getTime()); //1379426880000
console.log(date); //28-09-2019 3:40 GMT-0400
最佳答案
你可以试试这个。
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<script>
function getTimeAndDate(){
let today = new Date();
let date = today.getDate()+'/' + (today.getMonth()+1) + '/'+today.getFullYear();
let h = today.getHours();
let m =today.getMinutes();
console.log(h+':'+m);
console.log(date);
}
</script>
<body>
<input type="button" onclick="getTimeAndDate()" value="Button">
</body>
</html>
关于javascript - 如何将 jquery datepicker 格式转换为时间戳格式,如 dd-mm-yyyy (28/09/2019 3 :40pm),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58145335/