如何使用javascript将OLE Automation Date转换为可读格式? [英] How to convert OLE Automation Date to readable format using javascript?

查看:196
本文介绍了如何使用javascript将OLE Automation Date转换为可读格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您必须注意.NET方法DateTime.FromOADate(double d)。
我需要在javascript中实现相同的功能。即给予像40967.6424503935一样的双重值,它必须转换为2/28/2012 3:25:07 PM
有人可以帮我吗?

You must be aware of the .NET method "DateTime.FromOADate(double d)". I need to implement the same functionality in javascript. i.e given a double value like "40967.6424503935" it has to be converted to "2/28/2012 3:25:07 PM" Can someone please help me out?

提前感谢

推荐答案

自动化日期是从1900年1月1日起(1900年奇怪地被视为闰年)。所以转换是:

The automation date is the number of days since January 1, 1900 (with the year 1900 strangely being treated as a leap year). So a conversion is:

var oaDate = 40967.6424503935;
var date = new Date();
date.setTime((oaDate - 25569) * 24 * 3600 * 1000);
alert(date);

此解决方案创建一个UTC日期。显示时,会显示在您当地的时区。根据您的日期是当地日期还是UTC日期,这是正确的,或者需要一些额外的时区fiddling。

This solution creates a UTC date. When you display it, it'll be displayed in your local timezone. Depending on whether your date is a local date or a UTC date, this is correct or will require some additional timezone fiddling.

这篇关于如何使用javascript将OLE Automation Date转换为可读格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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