开发者

How to parse date in different languages

with browser language french i have a string which has date in the format v = 13/01/2010 10:54:00.

when i say Date.parse(v) i get the result as Date.parse(v) 1293897240000 Number

with browser language german i have a string which has date int he format v = 13.01.2010 10:54:00

when i say Date.parse(v) i get the result as Date.parse(v) NaN Number

can you please tell me how to parse date when it is in german language.

at the server side i converted date time to string as follows

if (currentIncidents[x].DateOccurred != null)

{

DateTime dt = (DateTime)currentInci开发者_StackOverflow中文版dents[x].DateOccurred;

incident.DateOccurred = dt.AddHours(b.TimeZoneOffset).ToShortDateString() + " " + dt.AddHours(b.TimeZoneOffset).ToLongTimeString();

if (dt.AddHours(b.TimeZoneOffset).IsDaylightSavingTime())

{

incident.DateOccurred = dt.AddHours(b.TimeZoneOffset).AddHours(-1).ToShortDateString() + " " + dt.AddHours(b.TimeZoneOffset).AddHours(-1).ToLongTimeString();

}

}

Thanks


Where does the date come from? If it is a user input, you should provide the user with a date selector control, which returns you a date object. If the date is from code, you should represent it as an date, no as a string. Fruther there is an ISO Standard for writing dates as string. Use that format.


Ext provides a Date.parseDate() function that accepts a format specifier. See docs.

Try this for german:

    Date.parseDate(v,"d.m.Y H.i.s")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜