Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
CUSTOM1 MomentJS vs Native Date
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser:
Chrome 134
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Moment
115670.8 Ops/sec
Native
221018.3 Ops/sec
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.0/moment.min.js'></script>
Tests:
Moment
moment('2017-09-29T11:23:40.483Z').add('MMM DD, YYYY hh:mm:ss A');
Native
let a = (date, format) => { const dateObj = typeof date === "string" || typeof date === "number" ? new Date(date) : date if (isNaN(dateObj.getTime())) { return "Invalid Date" } const day = dateObj.getDate() const month = dateObj.getMonth() + 1 const year = dateObj.getFullYear() let hours = dateObj.getHours() // Important: make hours mutable const minutes = dateObj.getMinutes() const seconds = dateObj.getSeconds() let ampm = hours >= 12 ? "PM" : "AM" // Calculate AM/PM // Convert 24-hour to 12-hour format if (format.includes("hh") || format.includes("h")) { hours = hours % 12 hours = hours ? hours : 12 // the hour '0' should be '12' } const replacements = { YYYY: String(year), YY: String(year).slice(-2), MM: String(month).padStart(2, "0"), M: String(month), DD: String(day).padStart(2, "0"), D: String(day), HH: String(hours).padStart(2, "0"), H: String(hours), hh: String(hours).padStart(2, "0"), // 12-hour format with leading zero h: String(hours), // 12-hour format without leading zero mm: String(minutes).padStart(2, "0"), m: String(minutes), ss: String(seconds).padStart(2, "0"), s: String(seconds), a: ampm.toLowerCase(), A: ampm } let formattedDate = format for (const [key, value] of Object.entries(replacements)) { formattedDate = formattedDate.replace(new RegExp(key, "g"), value) } return formattedDate } a('2017-09-29T11:23:40.483Z', 'MMM DD, YYYY hh:mm:ss A')