C # Date received from computer

I am trying to get a date in a string in C #. I need a format:

02/02/14

What is, YYYY.MM.DD

Can someone please let me know the command for this? And is there also a way to do, for example Date (-1)?

Thanks.

+4
source share
4 answers
  • System.DateTime.Now.ToString ("YYYY.MM.DD");
  • System.DateTime.Now.AddDays (-1)
+18
source

Declare the line as:

string mydate; myDate = DateTime.Now.ToString("yyyy.MM.dd"); messagebox.show(myDate); 
+1
source

For the first:

 string s = DateTime.Now.ToString("yyyy.MM.dd"); 

In the second case, you need to be explicit about what Date(-1) should return, but I expect it to include var foo = someDate.Add(timespan); or var foo = someDate.Add{SomeInterval}(delta);

0
source

You can do this using the DateTIMe ToString method, in more detail on MSDN

0
source

Source: https://habr.com/ru/post/1339605/


All Articles