Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String.Format DateTime value in decreasing number format c#?

Tags:

c#

DateTime input = DateTime.Now; //06/02/2011 04:05:07 PM
expectedOutput string = "20110602040507";

I want to get the above output string based on date following this ( year,month,day,hour,minute,second) pattern.

like image 901
DotNetDeveloper Avatar asked Sep 26 '26 01:09

DotNetDeveloper


2 Answers

You need the format string "yyyyMMddHHmmss", which will give hours in 24-hour format.

DateTime.Now.ToString("yyyyMMddHHmmss");
like image 200
Will A Avatar answered Sep 28 '26 16:09

Will A


Use DateTime.ToString method:

String format = "yyyyMMddHHmmss";
String formattedValue = input.ToString(format);
like image 25
Akram Shahda Avatar answered Sep 28 '26 16:09

Akram Shahda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!