js 获取系统服务器时间 而不获取系统(客户端)时间

1.获取服务器(项目部署机器)时间:

var now = new Date($.ajax({async: false}).getResponseHeader("Date"));

2.获取客户端(浏览器)时间:

var now = new Date();

3.其他时间方法:

获取年:

var currentYear = now.getFullYear();

获取月:

var currentMonth = now.getMonth();

获取日:

var currentDay = now.getDate();

获取小时:

var currentHours = now.getHours();

获取分钟:

var currentMinutes = now.getMinutes();

获取秒:

var currentSeconds = now.getSeconds();

获取毫秒:

var currentMilliseconds = now.getMilliseconds();

获取当前日期:

var currentDate = now.toLocaleDateString();

获取当前时间:

var currentTime = now.toLocaleTimeString();

获取日期和时间:

var dateTime = now.toLocaleString();

获取当前星期几:

var currentWeek = now.getDay();

获取完成年份:

var currentFullYear = now.getFullYear();

posted @ 2021-11-25 14:28  单纯的桃子  阅读(955)  评论(0编辑  收藏  举报