Format time in DataGridView to local timezone?

I handle this in CellFormatting event: private void OnCellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e. RowIndex ColumnIndex! = dgView.

Columns"TaskDate". Index) return; string cellValue = e. Value + " " + dgView.CurrentRow.CellsdgView.

Columns"TaskTime". Value); DateTime dtValue; DateTime. TryParse(cellValue, out dtValue); DateTime dtValueUTC = TimezoneInfo.

ConvertTimeToUtc(dtValue, "Eastern Time Zone"); e. Value = dtValueUTC.Value.ToLocalTime(); }.

The data that I am pulling in it a string version of the Time. The view I am using is returning the time as a varchar, so it doesn't know that the column is a DateTime field. – bluefeet Aug 26 at 17:15 Could you return the datetime field as is (that is datetime).

There after, at the client side where you have the gridview, you can use the Format property set to "mm/dd/yyyy" to "hh:mm:ss t". This would really help you for datetime values that happen between boundaries - for example, Aug 26th 5:00 PM Pacific time is actually Aug 27th Universal. – Arun Aug 26 at 17:20 I can't as I said in the original question, I am using a view that is begin used by multiple apps so I can't change it.

– bluefeet Aug 26 at 17:24 I have changed the snippet to suit your needs. You can improve upon it. You might want to (1) add a line of code at the end to update the time cell with the changed value (2) add formatting to your DataGridView "TaskDate" ("mm/dd/yyy") and "TaskTime" ("hh:mm:ss t") columns - you can do this at the initialize section where you bind your DataGridView.

– Arun Aug 26 at 18:22 Also, at the initialize section, you might need to set at least the TaskDate and TaskTime DataGridViewColumns's name. Like - . Name = yourDataGridViewColumnObject.

DataPropertyName = "TaskDate"; – Arun Aug 26 at 18:29.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions