js时间时间戳转换时间增加间隔等函数集合
代码语言:html
所属分类:其他
代码描述:js时间时间戳转换时间增加间隔等函数集合
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<script type="text/javascript"> /** *获取今天星期几 * */ function getWeekDate() { var now = new Date(); var day = now.getDay(); var weeks = new Array(7, 1, 2, 3, 4, 5, 6); var week = weeks[day]; return week; } /** *获取今天日期2020-10-12 * */ function getDate() { var today = new Date(); today.setTime(today.getTime()); return today.getFullYear()+"-" + (today.getMonth()+1) + "-" + today.getDate(); } /** *时间格式转换成时间戳 * */ function converttoTimeStamp(datestr) { datestr = datestr.replace(/-/g, '/'); // 将-替换成/,因为下面这个构造函数只支持/分隔的日期字符串 var date = new Date(datestr); // 构造一个日期型数据,值为传入的字符串 return date.getTime()/1000; } /** *时间戳转成时间格式 * */ function converttoDateStr(timestamp) { //num:0 YYYY-MM-DD num:1 YYYY-MM-DD hh:mm:ss // timestamp:时间戳 timestamp = timestamp+''; timestamp = timestamp.length == 10?timestamp*1000: timestamp; var date = new Date(timestamp); var y = date.getFullYear(); var m = date.getMonth() + 1; m = m < 10 ? ('0' + m): m; var d = date.getDate(); d = d < 10 ? ('0' + d): d; var h = date.getHours(); h = h < 10 ? ('0' + h): h; var minute = date.getMinutes(); var second = d.........完整代码请登录后点击上方下载按钮下载查看
网友评论0