GetTimezoneOffset / moment utcOffset

Benchmark created on


Description

some wild tests to get the users utc offset by vanilla js or moment

Preparation HTML

<script type="text/javascript" src="https://momentjs.com/downloads/moment-with-locales.min.js"></script>

Setup

let now = new Date()
let momentNow = moment()

Test runner

Ready to run.

Testing in
TestOps/sec
Vanilla - GetTimezoneOffset - Cached Date
-(now.getTimezoneOffset())
ready
Vanilla - GetTimezoneOffset - Current Date
-(new Date().getTimezoneOffset())
ready
Moment - UtcOffset - Cached Moment-Date
momentNow.utcOffset()
ready
Moment - UtcOffset - Current Moment Date
moment().utcOffset()
ready
Moment - GetTimezoneOffset - Cached Moment-Date - internal
momentNow._d.getTimezoneOffset()
ready
Moment - GetTimezoneOffset - Cached Moment-Date - toDate
momentNow.toDate().getTimezoneOffset()
ready
Vanilla - GetTimezoneOffset - Current Date - *-1
new Date().getTimezoneOffset() * -1
ready
Vanilla - GetTimezoneOffset - Cached Date - *-1
now.getTimezoneOffset() * -1
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.