将字符串格式化为日期字符串 [英] Formatting a String to a Date String
本文介绍了将字符串格式化为日期字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这让我很生气,应该很简单,
如何格式化日期字符串01122006是01/12 / 2006
我试过了
string teststr = String.Format(" {d}"," 01122006");
AND
string teststr = String.Format(" {## / ## / ####" ;,01122006;;
和其他各种方法,但这些抛出错误。
有人可以帮忙吗?
谢谢
Jon。
This is driving me mad, should be simple,
How can I format a date string "01122006" to be "01/12/2006"
I have tried
string teststr = String.Format("{d}","01122006");
AND
string teststr = String.Format("{##/##/####","01122006");
and various other methods but these throw errors.
Can someone help please ?
Thanks
Jon.
推荐答案
你需要让它成为一个datetime first,试试:
DateTime.ParseExact(" 01122006"," ddMMyyyy",
DateTimeFormatInfo.CurrentInfo).ToString(" dd / MM / yyyy);
Ciaran O'Donnell
" Bishman"写道:
You need to make it a datetime first, Try:
DateTime.ParseExact("01122006", "ddMMyyyy",
DateTimeFormatInfo.CurrentInfo).ToString("dd/MM/yyyy");
Ciaran O''Donnell
"Bishman" wrote:
这让我很生气,应该很简单,
如何格式化日期字符串01122006 ;是01/12 / 2006
我试过了
string teststr = String.Format(" {d}"," 01122006");
AND
string teststr = String.Format(" {## / ## / ####" ;,01122006;;
和其他各种方法,但这些抛出错误。
有人可以帮忙吗?
谢谢
Jon。
This is driving me mad, should be simple,
How can I format a date string "01122006" to be "01/12/2006"
I have tried
string teststr = String.Format("{d}","01122006");
AND
string teststr = String.Format("{##/##/####","01122006");
and various other methods but these throw errors.
Can someone help please ?
Thanks
Jon.
如果设置sDate =" 01122006" ;
您可以尝试
String.Format(" {0} / {1} / {2}",sDate.substring(0,2),sDate .substring(2,2),sda te.substring(4,4))
Gustavo。
Bishman < jo ************* @ btinternet.comwrote in message
news:eh ************** @ TK2MSFTNGP02。 phx.gbl ...
if you set sDate = "01122006"
You may try
String.Format("{0}/{1}/{2}",sDate.substring(0,2),sDate.substring(2,2),sDa te.substring(4,4))
Gustavo.
"Bishman" <jo*************@btinternet.comwrote in message
news:eh**************@TK2MSFTNGP02.phx.gbl...
这让我很生气,应该很简单,
如何格式化日期字符串01122006是01/12 / 2006
我试过了
string teststr = String.Format(" {d}"," 01122006");
AND
string teststr = String.Format(" {## / ## / ####" ;,01122006;;
和其他各种方法,但这些抛出错误。
有人可以帮忙吗?
谢谢
Jon。
This is driving me mad, should be simple,
How can I format a date string "01122006" to be "01/12/2006"
I have tried
string teststr = String.Format("{d}","01122006");
AND
string teststr = String.Format("{##/##/####","01122006");
and various other methods but these throw errors.
Can someone help please ?
Thanks
Jon.
谢谢你的回复,
我必须和其他类型的格式混在一起!
我会给这些回复,
Jon。
" Bishman" < jo ************* @ btinternet.comwrote in message
news:eh ************** @ TK2MSFTNGP02。 phx.gbl ...
Thanks for the replies,
I must have got mixed up with other types of formatting !
I will give these a go,
Jon.
"Bishman" <jo*************@btinternet.comwrote in message
news:eh**************@TK2MSFTNGP02.phx.gbl...
这让我很生气,应该很简单,
如何格式化日期字符串01122006是01/12 / 2006
我试过了
string teststr = String.Format(" {d}"," 01122006");
AND
string teststr = String.Format(" {## / ## / ####" ;,01122006;;
和其他各种方法,但这些抛出错误。
有人可以帮忙吗?
谢谢
Jon。
This is driving me mad, should be simple,
How can I format a date string "01122006" to be "01/12/2006"
I have tried
string teststr = String.Format("{d}","01122006");
AND
string teststr = String.Format("{##/##/####","01122006");
and various other methods but these throw errors.
Can someone help please ?
Thanks
Jon.
这篇关于将字符串格式化为日期字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文