Javascript时间格式问题

发布于 2024-11-13 22:12:03 字数 523 浏览 1 评论 0原文

我现在遇到了 Javascript 和名为“JMonthCalendar”的插件的问题。问题本质上是使用“Date(2011,6,6)”将返回如下信息:“Wed Jul 06 2011 00:00:00 GMT-0500 (Central Daylight Time)”。这不起作用,该插件确实如此 的

然后我尝试查找时间戳,但这也不是我想要的:“1311742800000”

我需要的是这样的:“2011-06-28T00:00:00.0000000”

是否有预先编程 如果没有,您建议我如何最好地做到这一点?

谢谢您的帮助

编辑:这是有问题的网站和页面,我现在正在测试它,如果它看起来很奇怪,那就是。为什么。-- http://powerqualityuniversity.net/?d=registration&p=calendar

I am having an issue with Javascript right now and a plugin named "JMonthCalendar". The problem is essentially that using the "Date(2011, 6, 6) will return information like this: "Wed Jul 06 2011 00:00:00 GMT-0500 (Central Daylight Time)". This will not work, the plugin does not read this format.

I then tried to look up timestamps, but this is not what I want either: "1311742800000"

What I need is something like this: "2011-06-28T00:00:00.0000000"

Is there a pre-programmed function for this? If not, how would you propose that I could best do it?

Thank you for your help.

EDIT: Here is the website and page that is in question, I am testing it right now so if it seems odd, thats why. -- http://powerqualityuniversity.net/?d=registration&p=calendar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娜些时光,永不杰束 2024-11-20 22:12:03

试试这个:

<script type="text/javascript">

function leadingZero(number) {
    return number < 10 ? "0" + number : number;
}

function formatDate(date) {
    return date.getFullYear() + "-" + 
        leadingZero(date.getMonth()) + "-"+
        leadingZero(date.getDate()) + "T" + 
        leadingZero(date.getHours()) + ":" + 
        leadingZero(date.getMinutes()) + ":" +
        leadingZero(date.getSeconds());
}

alert("formatted date: " + formatDate(new Date(2011, 6, 6)));

</script>

它可能不是最性感的解决方案,但由于 Javascript 没有任何内置的本机日期格式化功能,您需要自己实现它们。

Try this:

<script type="text/javascript">

function leadingZero(number) {
    return number < 10 ? "0" + number : number;
}

function formatDate(date) {
    return date.getFullYear() + "-" + 
        leadingZero(date.getMonth()) + "-"+
        leadingZero(date.getDate()) + "T" + 
        leadingZero(date.getHours()) + ":" + 
        leadingZero(date.getMinutes()) + ":" +
        leadingZero(date.getSeconds());
}

alert("formatted date: " + formatDate(new Date(2011, 6, 6)));

</script>

It might not be the sexiest solution, but since Javascript afaik doesn't have any native date formatting functionality built in you need to implement them yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文