Date EpochSeconds conversion

  • Thread starter Thread starter Kiran
  • Start date Start date
K

Kiran

Hi Folks,

Please advise me on the conversion of EpochSeconds to DD-MMM-YYYY format in c#.

given are the few examples.

1093128564
1093128537
1093128419

Thanks in advance.

Regards,
Kiran
 
Kiran,

From what I understand, this format is basically an offset in seconds
from a given epoch. To convert this, you want to have a DateTime value that
represents your Epoch (a static read only value, preferably). Once you have
that, you can get a TimeSpan instance that represents the seconds, and then
add it to the epoch DateTime to get the DateTime. So, for your values, you
would do this:

// Assume Epoch is a DateTime instance representing the Epoch.
DateTime dt1 = Epoch + new TimeSpan.FromSeconds(1093128564);

Hope this helps.
 
Hi Nicholas,

Thanks for your reply. Actually I am using a tool which returns this
EpochSeconds date. I don't know what is the DateTime value that
represents Epoch. Do you have any clue on initial set epoch...

Please assist.

Regards,
Kiran


Nicholas Paldino said:
Kiran,

From what I understand, this format is basically an offset in seconds
from a given epoch. To convert this, you want to have a DateTime value that
represents your Epoch (a static read only value, preferably). Once you have
that, you can get a TimeSpan instance that represents the seconds, and then
add it to the epoch DateTime to get the DateTime. So, for your values, you
would do this:

// Assume Epoch is a DateTime instance representing the Epoch.
DateTime dt1 = Epoch + new TimeSpan.FromSeconds(1093128564);

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Kiran said:
Hi Folks,

Please advise me on the conversion of EpochSeconds to DD-MMM-YYYY format
in c#.

given are the few examples.

1093128564
1093128537
1093128419

Thanks in advance.

Regards,
Kiran
 
Kiran,

I am not sure what the Epoch actually is. It technically could be
anything. You have to find out from the tool what it considers the Epoch to
be. Once you have that, the rest is easy.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Kiran said:
Hi Nicholas,

Thanks for your reply. Actually I am using a tool which returns this
EpochSeconds date. I don't know what is the DateTime value that
represents Epoch. Do you have any clue on initial set epoch...

Please assist.

Regards,
Kiran


Nicholas Paldino said:
Kiran,

From what I understand, this format is basically an offset in seconds
from a given epoch. To convert this, you want to have a DateTime value
that
represents your Epoch (a static read only value, preferably). Once you
have
that, you can get a TimeSpan instance that represents the seconds, and
then
add it to the epoch DateTime to get the DateTime. So, for your values,
you
would do this:

// Assume Epoch is a DateTime instance representing the Epoch.
DateTime dt1 = Epoch + new TimeSpan.FromSeconds(1093128564);

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Kiran said:
Hi Folks,

Please advise me on the conversion of EpochSeconds to DD-MMM-YYYY
format
in c#.

given are the few examples.

1093128564
1093128537
1093128419

Thanks in advance.

Regards,
Kiran
 
Hi Nicholas,

Thanks for your reply. Actually I am using a tool which returns this
EpochSeconds date. I don't know what is the DateTime value that
represents Epoch. Do you have any clue on initial set epoch...
<snip>
Epoch usually refers to the unix epoch time, which is January 1st,
1970 UTC. So:
DateTime dt=new DateTime(1970,1,1).AddSeconds(epochseconds);
Austin
 
Back
Top