Solved

date from UTC (seconds) to DateTime

Posted on 2008-06-17
5
1,705 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

622 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