如何在Javascript中将“常规日期"转换为unixtime? [英] How to convert Regular Date to unixtime in Javascript?

查看:141
本文介绍了如何在Javascript中将“常规日期"转换为unixtime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将看起来像12092008的日期转换为unixtime像这样的1221215809

How can i convert date which looks like this 12092008 to unixtime like this 1221215809

推荐答案

您可能要使用以下内容:

You may want to use the following:

function covertToUnixTime(yourDate) {
    return new Date(yourDate.substring(4, 8) + '/' + 
                    yourDate.substring(2, 4) + '/' + 
                    yourDate.substring(0, 2)).getTime() / 1000;
}

covertToUnixTime('12092008');   // Returns: 1221170400

这篇关于如何在Javascript中将“常规日期"转换为unixtime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆