getDay.js 639 B

123456789101112131415161718192021222324
  1. const getMillisecond = day => 1000 * 60 * 60 * 24 * day;
  2. export const digit = value => {
  3. return `${value}`.length === 1 ? `0${value}` : value;
  4. };
  5. export const format = dateStr => {
  6. if (dateStr.indexOf('-') > -1) {
  7. return dateStr.replace(/-/g, '/');
  8. }
  9. return dateStr;
  10. };
  11. export default ((day, showName) => {
  12. const date = new Date();
  13. date.setTime(date.getTime() + getMillisecond(day));
  14. const tYear = date.getFullYear();
  15. const tDate = digit(date.getDate());
  16. const tMonth = digit(date.getMonth() + 1);
  17. return {
  18. showName,
  19. date: [tYear, tMonth, tDate].join('-'),
  20. showDate: [tMonth, tDate].join('-')
  21. };
  22. });