index.js 800 B

1234567891011121314151617181920212223242526
  1. var parse = require('../parse/index.js')
  2. /**
  3. * @category Millisecond Helpers
  4. * @summary Set the milliseconds to the given date.
  5. *
  6. * @description
  7. * Set the milliseconds to the given date.
  8. *
  9. * @param {Date|String|Number} date - the date to be changed
  10. * @param {Number} milliseconds - the milliseconds of the new date
  11. * @returns {Date} the new date with the milliseconds setted
  12. *
  13. * @example
  14. * // Set 300 milliseconds to 1 September 2014 11:30:40.500:
  15. * var result = setMilliseconds(new Date(2014, 8, 1, 11, 30, 40, 500), 300)
  16. * //=> Mon Sep 01 2014 11:30:40.300
  17. */
  18. function setMilliseconds (dirtyDate, dirtyMilliseconds) {
  19. var date = parse(dirtyDate)
  20. var milliseconds = Number(dirtyMilliseconds)
  21. date.setMilliseconds(milliseconds)
  22. return date
  23. }
  24. module.exports = setMilliseconds