Solved

date from UTC (seconds) to DateTime

Posted on 2008-06-17
5
1,694 Views
Last Modified: 2012-08-13
My dataProvider comes in as an XML with the date in UTC (seconds) example: 1209139206.928

How can I convert this to a readable format and have it displayed in the dataField section?
 
<mx:DataGrid
				id="datagrid"				
				width="100%" height="100%"
				dataProvider="{dataProvider}">
				<mx:columns>
					<mx:DataGridColumn
						dataField="Date"/>								
				</mx:columns>
			</mx:DataGrid>

Open in new window

0
Comment
Question by:NewtonianB
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
Yiogi earned 500 total points
ID: 21807921
You basically have a UNIX timestamp and want a C$ date time I guess. I'll give you an example in C# asp.net.

After you execute the code below your dt variable will have the datetime you need. I don't know how to do it in flex sorry but the principle should be easy to apply.
// Assign your UNIX timestamp here
double timestampToConvert = 1209139206.928;
// Create a datetime that starts from 1st January 1970 as Unix timestamps do
DateTime dt = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
// Add the seconds in your UNIX timestamp
dt = dt.AddSeconds(timestampToConvert);

Open in new window

0
 

Author Comment

by:NewtonianB
ID: 21808138
hey thanks, Yiogi
The date is right but the time is off by about 4 hours.
I thought it would be greenwich time but greenwich time is 5 hours ahead of me and not 4, so i'm not sure what could be the problem.

How can I set the time correction for the time zone in C# to be automatic?

0
 
LVL 8

Assisted Solution

by:Yiogi
Yiogi earned 500 total points
ID: 21808143
Hi sorry I forgot it was UTC. You'll need to convert it to local time. So you can do:
dt = dt.ToLocalTime();

0
 
LVL 8

Expert Comment

by:Yiogi
ID: 21808156
btw about the 5 hours and not 4 don't forget that for the past couple of weeks in the US you have daylight saving time. So UTC is only 4 hours ahead of you until you go back to normal time. Don't confuse UTC with UK time. UK is also in daylight saving for a couple of months earlier than US so now your UK time difference is still 5 hours while it was 6 hours a month ago.
0
 

Author Comment

by:NewtonianB
ID: 21808328
ace! thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to translate path in URL with PHP? 11 48
wordpress limitations 4 135
Having Returning  Anonymous Function Access Global Function 7 112
Form submit issue 11 89
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question