date_common.js 787 B

1234567891011121314151617181920212223242526
  1. //当前日期
  2. function getNowDate() {
  3. var date = new Date();
  4. var year = date.getFullYear();
  5. var month = date.getMonth() + 1;
  6. var day = date.getDate();
  7. var hour = date.getHours();
  8. var minute = date.getMinutes();
  9. var second = date.getSeconds();
  10. return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);
  11. }
  12. /**
  13. * 获取多少天前的日期
  14. */
  15. function getDateBefore(days) {
  16. var now = new Date();
  17. var date = new Date(now.getTime() - days * 24 * 3600 * 1000);
  18. var year = date.getFullYear();
  19. var month = date.getMonth() + 1;
  20. var day = date.getDate();
  21. var hour = date.getHours();
  22. var minute = date.getMinutes();
  23. var second = date.getSeconds();
  24. return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);
  25. }