Moment.js moment().toString() 方法
moment().toString() 方法 用于以英文返回 Moment 对象的可读字符串。它类似于原生 Date 对象的 toString() 方法。返回结果包含星期、月份、日期、年份、时间和时区偏移量。
语法:
参数: 此方法不接受任何参数:
返回值: 此方法将返回一个Moment对象的字符串表示形式。
注意: 这个方法在普通的Node.js程序中不能工作,因为它需要全局安装或项目目录中安装了moment.js库。
moment.js可以使用以下命令进行安装:
安装 moment 模块:
下面的示例将演示Moment.js的 moment().toString() 方法。
示例1:
输出:
示例2:
输出:
参考: https://momentjs.com/docs/#/displaying/as-string/