如何使用jquery显示当前日期AM PM和CST

时间:2022-10-03 21:53:24

Im trying to show current Date with below format 7/28/2016 11:55:37 PM CST

我试图用以下格式显示当前日期7/28/2016 11:55:37 PM CST

1 个解决方案

#1


0  

Date is object of Javascript, Jquery also uses object of javaScript. I hope below code will be usefull for your.

Date是Javascript的对象,Jquery也使用javaScript的对象。我希望下面的代码对你有用。

function formatDate(date) {
  var hours = date.getHours();
  var minutes = date.getMinutes();
  var ampm = hours >= 12 ? 'pm' : 'am';
  hours = hours % 12;
  hours = hours ? hours : 12; // the hour '0' should be '12'
  minutes = minutes < 10 ? '0'+minutes : minutes;
  var strTime = hours + ':' + minutes + ' ' + ampm;
  return date.getMonth()+1 + "/" + date.getDate() + "/" + date.getFullYear() + "  " + strTime;
}

var d = new Date();
var e = formatDate(d);

alert(e);

#1


0  

Date is object of Javascript, Jquery also uses object of javaScript. I hope below code will be usefull for your.

Date是Javascript的对象,Jquery也使用javaScript的对象。我希望下面的代码对你有用。

function formatDate(date) {
  var hours = date.getHours();
  var minutes = date.getMinutes();
  var ampm = hours >= 12 ? 'pm' : 'am';
  hours = hours % 12;
  hours = hours ? hours : 12; // the hour '0' should be '12'
  minutes = minutes < 10 ? '0'+minutes : minutes;
  var strTime = hours + ':' + minutes + ' ' + ampm;
  return date.getMonth()+1 + "/" + date.getDate() + "/" + date.getFullYear() + "  " + strTime;
}

var d = new Date();
var e = formatDate(d);

alert(e);