How to Convert a date and time to epoch?

E

Extremest

I have a bunch of dates in a couple different formats. I would like to
convert them to epoch. The dates are like this

Mon, 12 Jun 2006 09:18:22 GMT
12 Jun 2006 10:37:28 GMT

I can do this in perl easily with the Date::Manip module but don't know
how to do it in c#. Is there a way to do this or do I need to right
something to parse each date?
 
H

hiteshmangal

Hi,

For that u can use DateTime class.

DateTime dt = new DateTime.Now;

By this u will get current date and time.

Thanks,
Hitesh
 
E

Extremest

I don't need to do the current one. I need to do ones that are in the
above format. Is that possible?
 
E

Extremest

OK I figured it out. Used datetime.parse to get it formatted then used
a little function to get the epoch.
 
H

hiteshmangal

Hi,


For that u can use below line for getting UTC/GMT time:-

DateTime dt = DateTime.UtcNow;

Thanks,
Hitesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top