Howdy, Stranger!

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

Categories

datetime conversion

havejeethavejeet Member Posts: 17
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 Member Posts: 17
    Little addition to the question,

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

    thanks
    Jeet
  • PsightoplazmPsightoplazm Member Posts: 332 ✭✭
    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 Member Posts: 17
    Thank you very much!

    Jeet
Sign In or Register to comment.