ionic时间戳转日期格式

版权声明:喜欢可以转载,但是必须注明出处。技术要分享,专利要维护。 https://blog.csdn.net/wzcyamadie/article/details/87990796

举例:
从1546323134000----转到“ 2019/1/1 14:12:14 ”
通过调用下面convertToDate()方法来达到目的。

	// 注意,参数为Long类型(我这里参数是从后端获取的)
	const ucheckTime = this.convertToDate(1546323134000);   
	//结果:ucheckTime  = ‘2019/1/1 14:12:14 ’

 	/**
     * 时间戳转string类型日期
     * 2019年2月27日20点53分
     */
    convertToDate(nows) {
        const now = new Date(nows);
        const year = now.getFullYear();
        const month = now.getMonth() + 1;
        const date = now.getDate();
        const hour = now.getHours();
        const minute = now.getMinutes();
        const second = now.getSeconds();
        return year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second;
    }

猜你喜欢

转载自blog.csdn.net/wzcyamadie/article/details/87990796