日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

时间(下)

發布時間:2024/1/18 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 时间(下) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

獲取當前的日期(返回格式: YYYY-mm-dd)

function getCurrentDate(date) {

let month = parseInt(date.getMonth() + 1);

let day = date.getDate();

if (month < 10) {

month = '0' + month

} if (day < 10) {

day = '0' + day ? } return date.getFullYear() + '-' + month + '-' + day; }

獲取本周的第一天

返回格式: YYYY-mm-dd

例子: 當日為: 2020-11-27

返回日期為: 2020-11-23

function getCurrentWeekFirstDay(date) {

let weekFirstDay = new Date(date - (date.getDay() - 1) * 86400000)

let firstMonth = Number(weekFirstDay.getMonth()) + 1

if (firstMonth < 10) {

firstMonth = '0' + firstMonth }

let weekFirstDays = weekFirstDay.getDate();

if (weekFirstDays < 10) {

weekFirstDays = '0' + weekFirstDays; } ? return weekFirstDay.getFullYear() + '-' + firstMonth + '-' + weekFirstDays; }

獲取本周的最后一天

返回格式: YYYY-mm-dd

例子: 當日為: 2020-11-27

返回日期為: 2020-11-29 function getCurrentWeekLastDay(date) {

let weekFirstDay = new Date(date - (date.getDay() - 1) * 86400000)

let weekLastDay = new Date((weekFirstDay / 1000 + 6 * 86400) * 1000)

let lastMonth = Number(weekLastDay.getMonth()) + 1

if (lastMonth < 10) {

lastMonth = '0' + lastMonth ? } ? let weekLastDays = weekLastDay.getDate();

if (weekLastDays < 10) {

weekLastDays = '0' + weekLastDays; } ? return weekFirstDay.getFullYear() + '-' + lastMonth + '-' + weekLastDays; }

獲取當前月的第一天

返回格式: YYYY-mm-dd

例子: 當日為: 2020-11-27

返回日期為: 2020-11-01 function getCurrentMonthFirstDay() {

let date = new Date();

date.setDate(1);

let month = parseInt(date.getMonth() + 1);

let day = date.getDate();

if (month < 10) {

month = '0' + month ? } if (day < 10) {

day = '0' + day }

return date.getFullYear() + '-' + month + '-' + day; }

獲取當前月的最后一天

返回格式: YYYY-mm-dd

例子: 當日為: 2020-11-27

返回日期為: 2020-11-30

function getCurrentMonthLastDay() {

let date = new Date();

let currentMonth = date.getMonth();

let nextMonth = ++currentMonth;

let nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1);

let oneDay = 1000 * 60 * 60 * 24;

let lastTime = new Date(nextMonthFirstDay - oneDay);

let month = parseInt(lastTime.getMonth() + 1);

let day = lastTime.getDate();

if (month < 10) {

month = '0' + month

}

if (day < 10) {

day = '0' + day } return date.getFullYear() + '-' + month + '-' + day; }

? let date = new Date(); // 例當日時間是 2020-11-27 getCurrentMonthIssue(date); ? ? ? ? // result: 2020-11 --期號 getCurrentDate(date); ? ? ? ? ? ? ? // result: 2020-11-27 --當前日期 getCurrentWeekFirstDay(date); ? ? ? // result: 2020-11-23 --本周第一天時間 getCurrentWeekLastDay(date); ? ? ? ?// result: 2020-11-29 --本周最后一天時間 getCurrentMonthFirstDay(date); ? ? ?// result: 2020-11-01 --本月第一天時間 getCurrentMonthLastDay(date); ? ? ? // result: 2020-11-30 --本月最后一天時間

獲取上周第一天日期

getLastWeekData(){

let lastweek={};

let date=new Date();

date.setDate(date.getDate() - 7 -date.getDay() + 1);

lastweek.start_day=date.getFullYear() + "-" +(date.getMonth()+1) + "-" +date.getDate();

return lastweek.start_day

},

獲取上周最后一天日期

getLastWeekData1(){

let lastweek={};

let date=new Date();

date.setDate(date.getDate() - 1 -date.getDay() + 1);

lastweek.end=date.getFullYear() + "-" +(date.getMonth()+1) + "-" + date.getDate();

return lastweek.end

},

獲取當季第一天

function getFirstDayOfSeason (date) { ? var month = date.getMonth(); ? if(month <3 ){ ? date.setMonth(0); ? }else if(2 < month && month < 6){ ? date.setMonth(3); ? }else if(5 < month && month < 9){ ? date.setMonth(6); ? }else if(8 < month && month < 11){ ? date.setMonth(9); ? } ? date.setDate(1); ? return timeFormat(date); }

總結

以上是生活随笔為你收集整理的时间(下)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。