Solved

convert "Number of seconds since January 1, 2008" to a date

Posted on 2011-09-07
5
317 Views
Last Modified: 2012-06-21
I'm given an integer which is the number of seconds since January 1, 2008. Is there a simple way to convert this to a date format?

Or do I have to do it the hard way (which I could, but I'd rather save myself the trouble.)
0
Comment
Question by:deleyd
5 Comments
 
LVL 22

Assisted Solution

by:p_davis
p_davis earned 50 total points
ID: 36498917
DateTime dt = new DateTime(2008, 1,1,0,0,0);
DateTime newDt =  dt.AddSeconds(DateTime.Now.Subtract(dt).TotalSeconds);'

haven't tested this but was the first thought
0
 
LVL 17

Accepted Solution

by:
OriNetworks earned 225 total points
ID: 36499141
DateTime myDate = new DateTime(2008,1,1,0,0,0).AddSeconds(MySeconds);
0
 
LVL 2

Assisted Solution

by:AJRDev
AJRDev earned 225 total points
ID: 36499216
Almost..

Where numSeconds is your integer value:

DateTime base = new DateTime(2008, 1,1,0,0,0);
DateTime dt =  base.AddSeconds(numSeconds);'
0
 
LVL 2

Expert Comment

by:AJRDev
ID: 36499223
Sorry oriNetworks.. didn't see ur post till after mine :)
0
 

Author Closing Comment

by:deleyd
ID: 36499251
Wow I'm glad it's easy so I don't have to do it the hard way.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 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

15 Experts available now in Live!

Get 1:1 Help Now