兰州专业网站建设公司泰安的网站建设公司
兰州专业网站建设公司,泰安的网站建设公司,大连网站建设具体流程是什么,云南省人防工程建设网站ES6版本
function countdown(endTime, includeSeconds true) {// 获取当前时间let now new Date();// 将传入的结束时间字符串转换为日期对象let endDateTime new Date(endTime);// 检查传入的时间字符串是否只包含日期#xff08;不包含时分秒#xff09;if (endTime.tr…ES6版本
function countdown(endTime, includeSeconds true) {// 获取当前时间let now new Date();// 将传入的结束时间字符串转换为日期对象let endDateTime new Date(endTime);// 检查传入的时间字符串是否只包含日期不包含时分秒if (endTime.trim().split( ).length 1) {// 如果只有日期则将时间设置为该日期的午夜00:00:00endDateTime.setHours(0, 0, 0, 0);}// 计算当前时间与结束时间的时间差单位毫秒let timeDifference endDateTime - now;// 计算剩余的天数、小时数、分钟数和秒数let days Math.floor(timeDifference / (24 * 3600 * 1000));let hours Math.floor((timeDifference % (24 * 3600 * 1000)) / (3600 * 1000));let minutes Math.floor((timeDifference % (3600 * 1000)) / (60 * 1000));let seconds Math.floor((timeDifference % (60 * 1000)) / 1000);// 构建倒计时字符串let countdownString ${days}天${hours}时${minutes}分;// 根据includeSeconds参数决定是否包含秒数if (includeSeconds) {countdownString ${seconds}秒;}return countdownString;
}// 示例用法
// countdown(2078-01-28); // 只有日期
// countdown(2078-01-28 12:30:00); // 日期和时间
// countdown(2078-01-28, false); // 只有日期不包含秒数ES5版本
function countdown(endTime, includeSeconds) {// 设置默认值如果includeSeconds未定义则默认为trueincludeSeconds typeof includeSeconds ! undefined ? includeSeconds : true;// 获取当前时间var now new Date();// 将传入的结束时间字符串转换为日期对象var endDateTime new Date(endTime);// 检查传入的时间字符串是否只包含日期不包含时分秒if (endTime.trim().split( ).length 1) {// 如果只有日期则将时间设置为该日期的午夜00:00:00endDateTime.setHours(0, 0, 0, 0);}// 计算当前时间与结束时间的时间差单位毫秒var timeDifference endDateTime - now;// 计算剩余的天数、小时数、分钟数和秒数var days Math.floor(timeDifference / (24 * 3600 * 1000));var hours Math.floor((timeDifference % (24 * 3600 * 1000)) / (3600 * 1000));var minutes Math.floor((timeDifference % (3600 * 1000)) / (60 * 1000));var seconds Math.floor((timeDifference % (60 * 1000)) / 1000);// 构建倒计时字符串var countdownString days 天 hours 时 minutes 分;// 根据includeSeconds参数决定是否包含秒数if (includeSeconds) {countdownString seconds 秒;}return countdownString;
}// 示例用法
// countdown(2078-01-28); // 只有日期
// countdown(2078-01-28 12:30:00); // 日期和时间
// countdown(2078-01-28, false); // 只有日期不包含秒数
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/88824.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!