Guest User

Untitled

a guest
Nov 19th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. export const DAY_TIMESTAMP = 60 * 60 * 24 * 1000
  2. export const HOUR_TIMESTAMP = 60 * 60 * 1000
  3. export const MINUTE_TIMESTAMP = 60 * 1000
  4.  
  5. export function formatDate(date, fmt) {
  6. const o = {
  7. 'M+': date.getMonth() + 1,
  8. 'd+': date.getDate(),
  9. 'h+': date.getHours(),
  10. 'm+': date.getMinutes(),
  11. 's+': date.getSeconds(),
  12. 'q+': Math.floor((date.getMonth() + 3) / 3),
  13. 'S': date.getMilliseconds()
  14. }
  15. if (/(y+)/.test(fmt)) {
  16. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
  17. }
  18. for (const k in o) {
  19. if (new RegExp('(' + k + ')').test(fmt)) {
  20. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
  21. }
  22. }
  23. return fmt
  24. }
  25.  
  26. export function getZeroDate(date) {
  27. const year = date.getFullYear()
  28. const month = date.getMonth() + 1
  29. const day = date.getDate()
  30. return new Date(year + '/' + month + '/' + day + ' 00:00:00')
  31. }
Add Comment
Please, Sign In to add comment