Solved

date from UTC (seconds) to DateTime

Posted on 2008-06-17
5
1,693 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

856 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