fiag
管理员
管理员
  • UID1188
  • 注册日期2004-12-21
  • 最后登录2024-04-22
  • 发帖数4681
  • 经验686枚
  • 威望0点
  • 贡献值402点
  • 好评度51点
阅读:5554回复:9

请教Date对象的toLocaleString函数在IE和Fx的差异

楼主#
更多 发布于:2005-05-09 14:02
var today;
   today = new Date();
   alert ( today.toLocaleString() );


toLocaleString在IE中显示格式为
2005年5月9日 13:57:46


在Fx中显示
Monday, May 09, 2005 13:55:50



为什么IE和Firefox又不统一呢? 是不是与系统依赖性有关系呢?
fiag
管理员
管理员
  • UID1188
  • 注册日期2004-12-21
  • 最后登录2024-04-22
  • 发帖数4681
  • 经验686枚
  • 威望0点
  • 贡献值402点
  • 好评度51点
1楼#
发布于:2005-05-09 14:02
The toLocaleString method relies on the underlying operating system in formatting dates. It converts the date to a string using the formatting convention of the operating system where the script is running. For example, in the United States, the month appears before the date (04/15/98), whereas in Germany the date appears before the month (15.04.98). If the operating system is not year-2000 compliant and does not use the full year for years before 1900 or over 2000, toLocaleString returns a string that is not year-2000 compliant. toLocaleString behaves similarly to toString when converting a year that the operating system does not properly format.
猫头猪
狐狸大王
狐狸大王
  • UID163
  • 注册日期2004-11-25
  • 最后登录2005-12-04
  • 发帖数595
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
2楼#
发布于:2005-05-09 14:02
最后搞定了么?
fiag
管理员
管理员
  • UID1188
  • 注册日期2004-12-21
  • 最后登录2024-04-22
  • 发帖数4681
  • 经验686枚
  • 威望0点
  • 贡献值402点
  • 好评度51点
3楼#
发布于:2005-05-09 14:02
不行。两个浏览器返回的结果不同,不能统一处理。变相解决吧get一堆。

按标准说,应该根据用户的操作系统设置来给出结果。
猫头猪
狐狸大王
狐狸大王
  • UID163
  • 注册日期2004-11-25
  • 最后登录2005-12-04
  • 发帖数595
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
4楼#
发布于:2005-05-09 14:02
能做个test case么?一个html文件就可以.
guoshuang
火狐狸
火狐狸
  • UID771
  • 注册日期2004-12-11
  • 最后登录2006-12-28
  • 发帖数134
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
5楼#
发布于:2005-05-09 14:02
javascript:alert(new Date().toLocaleString())

我这里 ff ie 显示一样
2005年5月12日 17:02:12

opera 显示
2005-5-12 17:01:33
fiag
管理员
管理员
  • UID1188
  • 注册日期2004-12-21
  • 最后登录2024-04-22
  • 发帖数4681
  • 经验686枚
  • 威望0点
  • 贡献值402点
  • 好评度51点
6楼#
发布于:2005-05-09 14:02
 截图。不知道为什么会这样?
猫头猪
狐狸大王
狐狸大王
  • UID163
  • 注册日期2004-11-25
  • 最后登录2005-12-04
  • 发帖数595
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
7楼#
发布于:2005-05-09 14:02
看了下代码,就是调用了一个strftime
http://lxr.mozilla.org/aviary101branch/ ... time.c#475
没有任何离奇的地方啊.
fiag
管理员
管理员
  • UID1188
  • 注册日期2004-12-21
  • 最后登录2024-04-22
  • 发帖数4681
  • 经验686枚
  • 威望0点
  • 贡献值402点
  • 好评度51点
8楼#
发布于:2005-05-09 14:02
如果toLocaleString是按照这个参数传递的话
http://lxr.mozilla.org/aviary101branch/ ... ate.c#1656

发觉我写的例程照样是 Thursday, May 12, 2005 23:56:02
怀疑是操作系统问题

#include <stdio.h>
#include <time.h>
int main(int argc, char* argv[])
{
	time_t t;
	time(&t);
	const long ct = t;
	char s[50];
	strftime(s, 50, "%#c", localtime(&ct));
	printf(s);
	printf("\n");
	return 0;
}
ja
ja
小狐狸
小狐狸
  • UID9447
  • 注册日期2005-10-25
  • 最后登录2005-10-26
  • 发帖数4
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
9楼#
发布于:2005-05-09 14:02
搞定了吗?
一定要分解处理吗?
游客

返回顶部