“2006年4月3日”的日期格式模式类型日期 [英] Date format pattern for "03rd of April 2006" type date

查看:77
本文介绍了“2006年4月3日”的日期格式模式类型日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在尝试通过指定格式将字符串转换为日期。价值

是这样的:2006年4月3日。现在通过使用

以下格式将其转换为正常:dd \\\\\\\\\•MMMM yyyy。问题当然是

字符串可以是...的第01个,等等,这意味着我不能使用\\\&#br / >
所有可能值的格式说明。


有什么建议吗?有没有我可以使用的通配符,比如dd \?\?和...


谢谢,

Zsolt

Hi,

I''m trying to convert a string to date by specifying the format. The value
is like this: "03rd of April 2006". Now this is converted fine by using the
following format: "dd\r\d \o\f MMMM yyyy". The problem is of course that the
string can be 01st of..., 04th of etc., meaning that I can''t use the "\r\d"
format description for all possible values.

Any suggestions? Is there a wildcard i can use, like "dd\?\?"...

Thanks,
Zsolt

推荐答案

如果找不到更好的方法,请尝试以下方法:


switch(theDateTime.Day)

{

案例1:

//使用st这里

案例2:

//使用nd这里

案例3:

//使用rd这里

默认:

//使用th这里

}


让我们为此写一个私人帮手。


希望它有所帮助,

Thi

If you find no better way, try something like this:

switch (theDateTime.Day)
{
case 1:
// use "st" here
case 2:
// use "nd" here
case 3:
// use "rd" here
default:
// use "th" here
}

Let''s write a private helper for this.

Hope it helps,
Thi


你好,


感谢您的建议,但我真的会喜欢不这样做:)。


format = new System.Globalization.CultureInfo(CultureInfo.Invar iantCulture.LCID,false);


System.DateTime DateValue = System.DateTime.ParseExact(inputString,formatDescription,format);


现在inputString是03rd of 2006年4月并且用户必须告诉我/ system formatDescription是什么。它不能给我rd。硬编码格式,所以问题是是否可以指定格式以覆盖st,nd和nd。等情况,或者我们必须有你建议的东西,必须解析格式和inputString并找出最终的格式。


问候,


Zsolt


" Truong Hong Thi" <第***** @ gmail.com>在消息新闻中写道:11 ********************* @ e56g2000cwe.googlegro ups.com ...
Hi T

Thanks for the suggestion but I would really like not to do that :).

format = new System.Globalization.CultureInfo(CultureInfo.Invar iantCulture.LCID, false);

System.DateTime DateValue = System.DateTime.ParseExact(inputString, formatDescription, format);

Now the inputString is "03rd of April 2006" and the user have to tell me/system what the formatDescription is. It can''t give me the "rd" hardcoded format, so question is if the format can be specified to cover the "st", "nd" etc cases, or we have to have something that you suggest and have to parse the format and the inputString and figure out the final format.

Regards,

Zsolt

"Truong Hong Thi" <th*****@gmail.com> wrote in message news:11*********************@e56g2000cwe.googlegro ups.com...
如果你找不到更好的尝试这样的事情:

切换(theDateTime.Day)
{
案例1:
//使用st这里
案例2:
//使用nd这里
案例3:
//使用rd这里
默认:
//使用th在这里
}

让我们为此写一个私人帮手。

希望它有所帮助,
Thi
If you find no better way, try something like this:

switch (theDateTime.Day)
{
case 1:
// use "st" here
case 2:
// use "nd" here
case 3:
// use "rd" here
default:
// use "th" here
}

Let''s write a private helper for this.

Hope it helps,
Thi





zsolt写道:

zsolt wrote:


我正在尝试将字符串转换为date指定格式。值
是这样的:2006年4月3日。现在使用
以下格式将其转换为正常:dd \\\\\\\,MMMM yyyy。问题当然是
字符串可以是...的第04个,等等,这意味着我不能使用\\\
格式描述所有可能的价值观。

有什么建议吗?是否有我可以使用的通配符,例如dd \?\?......
Hi,

I''m trying to convert a string to date by specifying the format. The value
is like this: "03rd of April 2006". Now this is converted fine by using the
following format: "dd\r\d \o\f MMMM yyyy". The problem is of course that the
string can be 01st of..., 04th of etc., meaning that I can''t use the "\r\d"
format description for all possible values.

Any suggestions? Is there a wildcard i can use, like "dd\?\?"...




看来没有。但是,如何从

输入字符串的前两个字符构建一个新字符串,再加上第九个字符

起,然后解析它?
< br $> b $ b -

Larry Lard

回复团体请



It appears not. However, how about constructing a new string from the
first two characters of the input string, plus the ninth character
onwards, and then parsing that?

--
Larry Lard
Replies to group please


这篇关于“2006年4月3日”的日期格式模式类型日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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