I want to convert a C# DateTime to "YYYYMMDDHHMMSS" format. But I don't find a built in method to get this format? Any comments?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
If you use ReSharper, get help with ':' (see image)
After spent a lot of hours on Google search, I found the below solution as when I locally give date time, no exception while from other server, there was Error......... Date is not in proper format.. Before saving/ searching Text box date time in C#, just checking either the outer Serer Culture is same like database server culture.. Ex both should be "en-US" or must be both "en-GB" asp below snap shot.
Even with different date format like (dd/mm/yyyy) or (yyyy/mm/dd), it will save or search accurately.
This site has great examples check it out
Standard DateTime Formatting
Update using c# 6 string interpolation format
You've just got to be careful between months (MM) and minutes (mm):
(Also note that HH is 24 hour clock, whereas hh would be 12 hour clock, usually in conjunction with t or tt for the am/pm designator.)
If you want to do this as part of a composite format string, you'd use:
For further information, see the MSDN page on custom date and time formats.
if you just want it displayed as a string
You can use a custom format string:
Substitute "hh" for "HH" if you do not want 24-hour clock time.