locked
Time Format RRS feed

  • Question

  • Hi......

    I have datagridview at my form........I want to change my coulmn format to local PC time format........ and as i change time format of my local pc then my column format also become change.....................

    Can anyone have suggest me............?

    Thanks in advance

    Friday, June 25, 2010 6:12 AM

Answers

  • Here is sample code, But you make sure you have not changed culture.

          dataGridView1.Columns[0].DefaultCellStyle.Format = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FullDateTimePattern;
          dataGridView1.Rows.Add(DateTime.Now);
    

    Regards
    Nayan Paregi (MCTS)
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Friday, June 25, 2010 6:38 AM
  • Hi Pratyaksh

     

    Welcome to MSDN forums!

     

    According to your description, I know that you want when you change time format of the local pc then the column format also become change. Right ?

     

    If you don’t use the value in another place, Nayan Paregi’s method is suitable.

    But if you also want to use the value with the local PC time format, you can use :

     

    string DateStr = dateValue.ToString(

    System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FullDateTimePattern

    );

    // dateValue is your value of DateTime type from sqlserver you have selected

     

     

    Then you can use this time format anywhere without the second convert statement.

     

    If I misunderstood you, please kindly elaborate your question.

    If anything is unclear, don’t hesitate to get in touch. I look forward to your reply.

    Best regards,

     

    Mike

    -------------------------------------------------------------------

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Monday, June 28, 2010 7:42 AM

All replies

  • Here is sample code, But you make sure you have not changed culture.

          dataGridView1.Columns[0].DefaultCellStyle.Format = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FullDateTimePattern;
          dataGridView1.Rows.Add(DateTime.Now);
    

    Regards
    Nayan Paregi (MCTS)
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Friday, June 25, 2010 6:38 AM
  • Hi Pratyaksh

     

    Welcome to MSDN forums!

     

    According to your description, I know that you want when you change time format of the local pc then the column format also become change. Right ?

     

    If you don’t use the value in another place, Nayan Paregi’s method is suitable.

    But if you also want to use the value with the local PC time format, you can use :

     

    string DateStr = dateValue.ToString(

    System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FullDateTimePattern

    );

    // dateValue is your value of DateTime type from sqlserver you have selected

     

     

    Then you can use this time format anywhere without the second convert statement.

     

    If I misunderstood you, please kindly elaborate your question.

    If anything is unclear, don’t hesitate to get in touch. I look forward to your reply.

    Best regards,

     

    Mike

    -------------------------------------------------------------------

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Monday, June 28, 2010 7:42 AM