Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

date from UTC (seconds) to DateTime

Posted on 2008-06-17
5
Medium Priority
?
1,723 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 2000 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 2000 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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

877 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