| |

VerySource

 Forgot password?
 Register
Search
View: 759|Reply: 6

Strange question, why does formatting my time as MM / dd / yyyy form MM-dd-yyyy

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-31 14:00:02
| Show all posts |Read mode
string a = System.DateTime.Now.ToString ("MM / dd / yyyy");

a would equal 01-04-2017


In ASP.Net, "/" becomes "-", which is not what I want, but if it is a Window Form program, the execution is normal and strange! How to solve it
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-3-21 00:00:02
| Show all posts
string a = System.DateTime.Now.ToString ("MM '/' dd '/' yyyy");
Reply

Use magic Report

0

Threads

26

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-3-21 11:45:01
| Show all posts
DateTime.Now.ToString ("MM / dd / yyyy"). Replace ("-", "/")
Reply

Use magic Report

0

Threads

32

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-3-22 09:45:01
| Show all posts
It has something to do with the locale, so:
DateTime.Now.ToString ("MM / dd / yyyy", CultureInfo.InvariantCulture)
Reply

Use magic Report

0

Threads

29

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-4-4 07:15:01
| Show all posts
I think this is unresolved
I have never tried the bad idea I thought.
DateTime.Now.ToString (@ "MM / dd / yyyy");

Reply person:江南小色
?

It has something to do with regional settings, like this:
DateTime.Now.ToString ("MM / dd / yyyy", CultureInfo.InvariantCulture)
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-7 12:30:01
| Show all posts
DateTime.Now.ToString ("yyyy / MM / dd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
Reply

Use magic Report

0

Threads

24

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-4-7 18:00:02
| Show all posts
DateTime.Now.ToString (@ "MM / dd / yyyy");
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list