Skip to content
Advertisement

How to use Mozilla DevNet date polyfill in JavaScript

I wish to use the date polyfill mentioned here at MDN:

if (!Date.now) {
  Date.now = function now() {
    return new Date().getTime();
  };
}

How do I get this into a variable? I tried:

function get_date_string(){
    if (!Date.now) {
        Date.now = function() { return new Date().getTime(); }
    }
}

var ds = get_date_string();

Advertisement

Answer

Use it this way:

if (!Date.now) {
  Date.now = function now() {
    return new Date().getTime();
  };
}

var ds = Date.now();
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement