Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 107,167 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 1,319 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Unix Times in DataGridView

 
Reply to this topicStart new topic

Unix Times in DataGridView

Echilon
post 4 Aug, 2008 - 07:36 AM
Post #1


New D.I.C Head

*
Joined: 23 Feb, 2007
Posts: 12


My Contributions


I have a DataGridView which gets data from a DataSet, one of the columns in the DataSet has an integer (a unix timestamp). I need to display the timestamp as a formatted DateTime, but I can't figure out how. I have a static method which converts unix times to DateTimes, but I can't find any examples on how to call the method when setting the value of the cell.
User is offlineProfile CardPM

Go to the top of the page


zakary
post 5 Aug, 2008 - 04:50 AM
Post #2


D.I.C Regular

Group Icon
Joined: 15 Feb, 2005
Posts: 370



Thanked 4 times

Dream Kudos: 175
My Contributions


The following is how to covert unix or posix time to datetime and back. you may need to convert it to a string to place it in your datagrid

csharp

int posixTime = someIntTiime;
double timestamp = Convert.ToDouble(posixTime);

// System.DateTime equivalent to the Unix/POSIX
System.DateTime currentDateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);

// add the number of seconds in Unix/POSIX
currentDateTime = currentDateTime.AddSeconds(timestamp);

// and to convert it back is
double time = (currentDateTime - new DateTime(1970, 1, 1)).TotalSeconds;

int timeToPosix = Convert.ToInt32(time);


This post has been edited by zakary: 5 Aug, 2008 - 04:54 AM
User is offlineProfile CardPM

Go to the top of the page

Echilon
post 5 Aug, 2008 - 07:57 AM
Post #3


New D.I.C Head

*
Joined: 23 Feb, 2007
Posts: 12


My Contributions


Thanks, but I said I had a static method for converting the times. wink2.gif

I eventually managed it by using the CellFormatting event of the DataGridView.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/27/08 09:41PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month