Moment.js set the base time from the server

前端 未结 3 749
难免孤独
难免孤独 2020-12-05 00:35

I have been reading the documentation, and cannot seem to find a method to set the date from the server as opposed to the client?

For example something like this

3条回答
  •  清歌不尽
    2020-12-05 01:20


    title: Changing Time Source version: 2.11.0 signature: |

    moment.now = function () { return +new Date(); }

    If you want to change the time that Moment sees, you can specify a method that returns the number of milliseconds since the Unix epoch (January 1, 1970).

    The default is:

    moment.now = function () {
        return +new Date();
    }
    

    This will be used when calling moment(), and the current date used when tokens are omitted from format(). In general, any method that needs the current time uses this under the hood.

    Changing Time Source

提交回复
热议问题