简体   繁体   中英

Convert from DateTime to TimeStamp

I am trying to convert a DateTime variable to Timestamp . My variable has the current format : 1/23/17 2:14:31 PM and I would like it to be TimeStamp like so I can use it for Oracle SQL Developer. eg: 23-JAN-17 2.14.31.000000000 PM .

I have tried to convert it like this:

DateTime d = DateTime.Now.AddDays(-31);
Console.WriteLine(d.ToUniversalTime().ToString("O"));

but the output is nothing like TimeStamp :

2017-01-23T14:14:31.5838355Z

Try this:

DateTime d = DateTime.Now.AddDays(-31);
long epoch = (d.Ticks - 621355968000000000) / 10000000;
Console.WriteLine(d.ToUniversalTime().ToString("dd-MMM-yy HH:mm:ss") + ":" + epoch);

Try this one

DateTime d = DateTime.Now.AddDays(-31);
Console.WriteLine(d.ToUniversalTime().ToString("hh-MMM-yy hh.mm.ss.ffffff tt"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM