datetime conversion - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

datetime conversion

havejeethavejeet Posts: 17Member
Hi All,

I want to convert current datetime (differs in format depending regional setting) into 20090622172120 format.
How do I do that? I want solution that work with any regional setting.

many thanks,

Jeet

Comments

  • havejeethavejeet Posts: 17Member
    Little addition to the question,

    I also required to convert that format back in original string. Please suggest.

    thanks
    Jeet
  • PsightoplazmPsightoplazm Posts: 332Member ✭✭
    use a date-time formatter to format and parse with:

    [code]
    var format = new DateTimeFormatInfo();
    format.LongDatePattern = "yyyyMMddHHmmss";
    var time = DateTime.Now;
    var str = time.ToString("D", format);
    MessageBox.Show(str);
    var time2 = DateTime.ParseExact(
    str,
    "D",
    format);
    MessageBox.Show(time2.ToString());
    [/code]
    ><//~Psightoplasm`~
  • havejeethavejeet Posts: 17Member
    Thank you very much!

    Jeet
Sign In or Register to comment.