在C#中获取特殊的日期模式 [英] Get special pattern of date in C#

查看:72
本文介绍了在C#中获取特殊的日期模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要求以dd \ / mm \ / yyyy格式设置日期我试过



string date = dy + @\ +/+ mn + @\+/+ yy;



但在调试期间,我指定的值变为dd \\ / mm \\ / yyyy我也试过



string test = date.Replace(\\,@\);



它会改变输出值,但我必须在服务器端分配值并使用进一步发布....请帮助

解决方案

日期没有特殊格式 - 它不是字符串。

如果你想要一个以特殊方式显示日期的字符串,你可以使用日期的toString-Command。在这里,您可以根据需要构建Output-String。

 myString = myDate.toString(  MMMM mm.yyyy); 

...或者你想要的。

参考toString-Placeholder的解释......


你想用结果字符串做什么?以下代码应该有效:

   string  date = dy +   \\ / + mn +   \\ / + yy;  



或者,如果您的值已经在DateTime对象中,那么可以使用:

  string  date = sDate.ToString(  dd \\\\\ / MM \\\\ / yy); 

//

string date = sDate.ToString( @ dd \\ / MM\\ / YY);


I have a require of of setting date in format of dd\/mm\/yyyy i tried

string date = dy + @"\" + "/" + mn + @"\" + "/" + yy;

but during debug where i assign value becomes dd\\/mm\\/yyyy i also tried

string test = date.Replace("\\",@"\");

it changes value in output but i have to assign value on server side and use futher for posting....please help

解决方案

Date has no special Format - it isn't a string.
If you want a string, which Displays your Date in a special way you could use the toString-Command of Date. Here you could build up your Output-String as you want.

myString = myDate.toString("MMMM mm.yyyy") ;

... or what you want.
Refer the decription of the toString-Placeholders ...


What are you trying to do with the resulting string? The following code should work:

string date = dy + "\\/" + mn + "\\/" + yy;


Alternatively if your values are already in a DateTime object you could just use:

string date = sDate.ToString("dd\\\\/MM\\\\/yy");

// or

string date = sDate.ToString(@"dd\\/MM\\/yy");


这篇关于在C#中获取特殊的日期模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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