Solved

date from UTC (seconds) to DateTime

Posted on 2008-06-17
5
1,687 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
ace! thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
WSDL Soap Error 12 241
Perl 101 11 67
How to translate path in URL with PHP? 11 31
Select distinct 25 60
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…
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.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now