请帮助日期 [英] Please Help with Dates

查看:67
本文介绍了请帮助日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题似乎取决于计算机系统设置。

当系统日期设置为M / d / yyyy但我确实没有问题

将系统日期设置为d / M / yyyy时出现问题。


我在网页上有一个文本框,其中包含日期ie)

document.frmTimesheet.tWeekFrom.value = 19/12/2004


theDate = new Date(document.frmTimesheet.tWeekFrom.value);


//拆分为日,月,年

iDay = theDate.getDate();

iMonth = theDate.getMonth()+ 1;

iYear = theDate.getFullYear();


alert(iDay);

alert(iMonth);

alert( iYear);


iday = 12

iMonth = 07

iYear = 2005


如果有任何方法可以做到这一点,我们将非常感谢任何帮助。

This problem seems to occur dependant on the computer system settings.
I have no issues when the system date is set as M/d/yyyy but I do
have a problem with the system date set as d/M/yyyy.

I have a text box on a web page that holds the date ie)
document.frmTimesheet.tWeekFrom.value = 19/12/2004

theDate = new Date(document.frmTimesheet.tWeekFrom.value);

// split into day, month, year
iDay = theDate.getDate();
iMonth = theDate.getMonth()+1;
iYear = theDate.getFullYear();

alert(iDay);
alert(iMonth);
alert(iYear);

iday= 12
iMonth= 07
iYear= 2005

If there is any way to do this any help would be greatly appreciated.

推荐答案

2004年12月14日11:44:50 -0800,布伦特韦伯斯特< br *** @ webstyler.ca>写道:


[snip]
On 14 Dec 2004 11:44:50 -0800, Brent Webster <br***@webstyler.ca> wrote:

[snip]
document.frmTimesheet.tWeekFrom.value = 19/12/2004

theDate = new Date(document.frmTimesheet.tWeekFrom.value);
document.frmTimesheet.tWeekFrom.value = 19/12/2004

theDate = new Date(document.frmTimesheet.tWeekFrom.value);




没有具体的定义来指定字符串应该如何

解析。这完全取决于实施。这可能意味着解析

将取决于区域设置,或者它可能固定为某种格式的

格式。


在我看来,自己解析字符串并使用

其他形式的Date构造函数更安全:


var date = new日期(年,月,日,小时,分钟,秒,毫秒);


虽然在你的情况下,你只需要担心前三个

参数。


当然,另一个问题是你接受的格式。

最好避免dd / mm / yyyy和mm / dd / yyyy,除非你只吸引那些使用其中一个的观众。


[snip]


Mike


-

Michael Winter

替换.invalid与.uk通过电子邮件回复。



There is no concrete definition that specifies how a string should be
parsed. It''s entirely up to the implementation. That may mean that parsing
would depend on the locale settings, or it may be fixed to a certain set
of formats.

In my opinion, it''s far safer to parse the string yourself and use the
other form of Date constructor:

var date = new Date(year, month, day, hr, min, sec, ms);

though in your case, you only need to worry about the first three
arguments.

Of course, the other concern is what formats you accept. It''s best to
avoid dd/mm/yyyy and mm/dd/yyyy unless you''ll only attract audiences that
uses one of those.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.


Brent Webster于2004年12月14日在comp.lang.javascript写了
Brent Webster wrote on 14 dec 2004 in comp.lang.javascript:
document.frmTimesheet.tWeekFrom.value = 19/12/2004

theDate = new Date(document.frmTimesheet.tWeekFrom.value);
document.frmTimesheet.tWeekFrom.value = 19/12/2004

theDate = new Date(document.frmTimesheet.tWeekFrom.value);




d =" 19/12/2004"


a = d.split(" /")


theDate = new Date(a [2],a [1] -1,a [0]);

-

Evertjan。

荷兰。

(请在我的电子邮件地址中将x'变为点数)



d = "19/12/2004"

a = d.split("/")

theDate = new Date(a[2],a[1]-1,a[0]);
--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


有没有办法确定用户如何进行计算机设置

配置?


我正在考虑使用验证,但如果月份有效,它仍将是

是错的


例如。)06/10/2004将是一个有效的日期但是如果设置了d / m / y它将解析

与Windows中的m / d / y不同

认为它是2004年10月10日而不是Jun e 10/2004


和13/06/2004是2005年6月1日将月份从13改为1并逐年推进

br />

日历控件正在加载文本框并使用系统日期

包括格式。

如果我不知道如何系统正在查看这个,我该如何解析它

正确。


如果系统日期格式= d / m / yy那么

d =" 13/12 / 2004 ''这将是过去的日期

a = d.split(" /")

theDate = new Date(a [2],a [1] - 1,a [0]);


Else

d =" 12/13/2004" ''这将是过去的日期

theDate = new Date(d);


结束如果


谢谢,


Brent


用.ca替换nospam以获取正确的电子邮件地址


***通过开发人员指南 http://www.developersdex.com 发送***

不要只是参加USENET ......获得奖励!
Is there a way to determine how the user has their computer settings
configured?

I was thinking of using a verify but if the month is valid it will still
be wrong

eg.) 06/10/2004 will be a valid date but if d/m/y is set it will parse
differently vs. m/d/y in Windows
Thinks it is Oct 10/2004 instead of June 10/2004

and 13/06/2004 is 01/06/2005 moving the month from 13 to 1 and advancing
the year by one

A calendar control is loading the text boxes and uses the system date
including the format.
If I do not know how the system is looking at this, how can I parse it
correctly.

If system date format = d/m/yy then
d = "13/12/2004" ''This would be the passed date
a = d.split("/")
theDate = new Date(a[2],a[1]-1,a[0]);

Else
d = "12/13/2004" ''This would be the passed date
theDate = new Date(d);

end if

Thanks,

Brent

replace nospam with .ca for correct e-mail address

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!


这篇关于请帮助日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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