timezoneOffset.js 410 B

12345678910111213141516
  1. var pad = require('../number/pad');
  2. /**
  3. * time zone as hour and minute offset from UTC (e.g. +0900)
  4. */
  5. function timezoneOffset(date){
  6. var offset = date.getTimezoneOffset();
  7. var abs = Math.abs(offset);
  8. var h = pad(Math.floor(abs / 60), 2);
  9. var m = pad(abs % 60, 2);
  10. return (offset > 0? '-' : '+') + h + m;
  11. }
  12. module.exports = timezoneOffset;