Formatting a datetime

  • Thread starter Thread starter Eric Stott
  • Start date Start date
E

Eric Stott

I need to take System.DateTime.Now and have the resulting text be in the
following format:
yyyyMMddhh24mmsss
I am using System.Convert.ToString(System.DateTime.Now), but I need to
format it correctly, what is the easiest way to accomplish this?
 
Eric,

I assume by

yyyyMMddhh24mmsss

What you really mean is four digit year, two digit month, two digit day,
two digit hour (in military time), two digit minute, two digit second (I
dont know what the third s is for). All digits will have a trailing zero,
if necessary.

Your pattern is:

yyyyMMddHHmmss

Hope this helps.
 
Yes that is the pattern.
Nicholas Paldino said:
Eric,

I assume by

yyyyMMddhh24mmsss

What you really mean is four digit year, two digit month, two digit
day, two digit hour (in military time), two digit minute, two digit second
(I dont know what the third s is for). All digits will have a trailing
zero, if necessary.

Your pattern is:

yyyyMMddHHmmss

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Eric Stott said:
I need to take System.DateTime.Now and have the resulting text be in the
following format:
yyyyMMddhh24mmsss
I am using System.Convert.ToString(System.DateTime.Now), but I need to
format it correctly, what is the easiest way to accomplish this?
 
I guess Nicholas meant to say you have to use:

System.DateTime.Now.ToString("yyyyMMddHHmmss") ;

/LM


Eric Stott said:
Yes that is the pattern.
Nicholas Paldino said:
Eric,

I assume by

yyyyMMddhh24mmsss

What you really mean is four digit year, two digit month, two digit
day, two digit hour (in military time), two digit minute, two digit
second (I dont know what the third s is for). All digits will have a
trailing zero, if necessary.

Your pattern is:

yyyyMMddHHmmss

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Eric Stott said:
I need to take System.DateTime.Now and have the resulting text be in the
following format:
yyyyMMddhh24mmsss
I am using System.Convert.ToString(System.DateTime.Now), but I need to
format it correctly, what is the easiest way to accomplish this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top