Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How convert UTC/GMT Time to Date Time in C#

Posted on 2009-07-10
4
Medium Priority
?
3,150 Views
Last Modified: 2013-12-17
I have a numeric field in sql 2000 server, numeric (10,0) not null.It represents the seconds from 1/1/1970.I want to convert this numeric to C# Date Time.
0
Comment
Question by:nikavak
[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
  • 2
4 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 24822596
This will convert from DateTime to UCTTimestamp so you just need to inverse it.
DateTime temp = ((DateTime)reader["UTCTime"]).ToUniversalTime();
transactionInfo.UtcTimeStamp = (long)temp.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;

Open in new window

0
 

Author Comment

by:nikavak
ID: 24822723
I dont understand this solution.I remark that i have a numeric (10,0) sql server field and I want to convert it to local time.This Field means the seconds since 1/1/1970
0
 

Author Comment

by:nikavak
ID: 24823488
I found the following solution

long ccc = 1228893007; //FROM DATABASE
            DateTime temp = new DateTime(ccc *10000000);//for each tick=100 nanoseconds
            DateTime temp1 = new DateTime(1970, 1, 1,00,00,00);
           

           
            DateTime transactionInfo;
            transactionInfo = new DateTime(temp1.Ticks + (ccc*10000000));
            transactionInfo = transactionInfo.ToLocalTime();
           

Best regards,
nikavak
0
 
LVL 1

Accepted Solution

by:
RSBuTCHeR earned 2000 total points
ID: 24838956
The solution is very simple. You know the ammount of seconds from 1-1-1970 till the date you want to show.
So you can just add the number of seconds to the date of 1-1-1970.

Best regards,

Falcko
            //Timestamp from database
            long timeStamp = 1000000000;
 
            //Start date (1-1-1970)
            DateTime startDate = new DateTime(1970, 1, 1);
 
            //Calculate the date
            DateTime endDate = startDate.AddSeconds(timeStamp);

Open in new window

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

730 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