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

Posted on 2011-09-07
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.)
Question by:deleyd
LVL 22

Assisted Solution

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
LVL 17

Accepted Solution

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

Assisted Solution

AJRDev earned 225 total points
ID: 36499216

Where numSeconds is your integer value:

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

Expert Comment

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

Author Closing Comment

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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Eagerly loading related objects in entity framework 5 29
Wav problem 4 25
Coding C# in Linux 8 60
Best resource to learn entity framework 2 32
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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

14 Experts available now in Live!

Get 1:1 Help Now