get-week-date
v1.0.1
Published
获取从今天(包括今天)开始往前7天或者往后7天的周几和日期
Downloads
2
Maintainers
Readme
获取从今天(包括今天)开始往前7天或者往后7天的周几和日期
usage:
/**
* @method getWeekDate
* @param {type} dateTime - 现在的时间戳 timestamp now
* @param {number} type - 往前7天还是往后7天,取值有2种:0或者1,0代表从今天往前推6天,1代表0代表从今天往后推6天
* 7 days ago or 7 days later, there are 2 kinds of values: 0 or 1,0 represents 6 days forward from today, 1 represents 0 represents 6 days from today
* @param {string} locale - 英文en,中文cn en represent english cn represent chinese
* @return {Array} week - week数组
*
*
* eg:
*
* let now = new Date();
let weekAndDate = getWeekDate(now,1);
console.log(weekAndDate);
//打印结果:[
// { dateStr: '2021-06-21', weekStr: '周一', date_short: '21' },
// { dateStr: '2021-06-22', weekStr: '周二', date_short: '22' },
// { dateStr: '2021-06-23', weekStr: '周三', date_short: '23' },
// { dateStr: '2021-06-24', weekStr: '周四', date_short: '24' },
// { dateStr: '2021-06-25', weekStr: '周五', date_short: '25' },
// { dateStr: '2021-06-26', weekStr: '周六', date_short: '26' },
// { dateStr: '2021-06-27', weekStr: '周日', date_short: '27' }
// ]
let now = new Date();
let weekAndDate = getWeekDate(now,0);
console.log(weekAndDate);
//打印结果:[
// { dateStr: '2021-06-21', weekStr: '周一', date_short: '21' },
// { dateStr: '2021-06-22', weekStr: '周二', date_short: '22' },
// { dateStr: '2021-06-23', weekStr: '周三', date_short: '23' },
// { dateStr: '2021-06-24', weekStr: '周四', date_short: '24' },
// { dateStr: '2021-06-25', weekStr: '周五', date_short: '25' },
// { dateStr: '2021-06-26', weekStr: '周六', date_short: '26' },
// { dateStr: '2021-06-27', weekStr: '周日', date_short: '27' }
// ]
*
]
* @description:
* @author: nykee
* @date: 2021/6/21
*/
import getWeekDate from 'get-week-date';
let now = new Date();
let weekAndDate = getWeekDate(now,1);
console.log(weekAndDate);
//打印结果:[
// { dateStr: '2021-06-21', weekStr: '周一', date_short: '21' },
// { dateStr: '2021-06-22', weekStr: '周二', date_short: '22' },
// { dateStr: '2021-06-23', weekStr: '周三', date_short: '23' },
// { dateStr: '2021-06-24', weekStr: '周四', date_short: '24' },
// { dateStr: '2021-06-25', weekStr: '周五', date_short: '25' },
// { dateStr: '2021-06-26', weekStr: '周六', date_short: '26' },
// { dateStr: '2021-06-27', weekStr: '周日', date_short: '27' }
// ]
let now = new Date();
let weekAndDate = getWeekDate(now,0);
console.log(weekAndDate);
//打印结果:[
// { dateStr: '2021-06-21', weekStr: '周一', date_short: '21' },
// { dateStr: '2021-06-22', weekStr: '周二', date_short: '22' },
// { dateStr: '2021-06-23', weekStr: '周三', date_short: '23' },
// { dateStr: '2021-06-24', weekStr: '周四', date_short: '24' },
// { dateStr: '2021-06-25', weekStr: '周五', date_short: '25' },
// { dateStr: '2021-06-26', weekStr: '周六', date_short: '26' },
// { dateStr: '2021-06-27', weekStr: '周日', date_short: '27' }
// ]