What does "s" do as a format specifier?

Is ":s" in this expression string.format("{0:s}", "hello world") just means that the variable is a string? I just don't know why anyone would do this.

I found this in the code and would like to remove the ":s" , but I want to make sure that I do not change the behavior.

+4
source share
1 answer

This is a Sortable specifier for standard date and time strings.

In your case (line printing) I think this does not affect the output

The specifier affects the DateTime value, converting it to a display format suitable for sorting.
For example, calling this code

  string result = string.Format("-{0:s}-", DateTime.Now); Console.WriteLine(result) 

will print

 2013-09-04T19:27:56 
+6
source

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


All Articles