The Evernote API and local SQLite database use a unusual format/type for date/time. I have C# functions that do the conversion, but I need the same functions in JavaScript.
I need two conversion functions:
1. Convert Evernote Date/Time TO JavaScript Date/Time.
2. Convert JavaScript Date/Time TO Evernote Date/Time
Can anyone help? I know nothing about C#. I have searched here and the Evernote forums, but could not find a solution.
This is NOT an exact duplicate of the indicated question:
"I am storing time in a MySQL database as a Unix timestamp and that gets sent to some JavaScript code. How would I get just the time out of it?"
for these reasons:
1. I'm asking for conversion in both directions, whereas the other question is asking for only one way.
2. I'm dealing with SQLite whereas the other question is dealing with MySQL
public DateTime ConvertEvernoteDateToDateTime(long evDate)
{
// convert from seconds to ticks
TimeSpan ts = new TimeSpan((evDate * 10000));
// create a date with the standard web base of 01/01/1970
// add the timespan difference
DateTime date = new DateTime(1970, 1, 1).Add(ts);
// adjust for the current timezone
ts = TimeZone.CurrentTimeZone.GetUtcOffset(date);
date = date.Add(ts);
return date;
}
public long ConvertDateTimeToEvernoteDate(DateTime date)
{
// adjust for the current timezone
date = date.ToUniversalTime();
// get the ticks as a base for the standard web base date
long baseOffset = new DateTime(1970, 1, 1).Ticks;
// get the difference between the base and our date
long evDate = date.Ticks - baseOffset;
// convert from ticks to seconds
evDate = evDate / 10000;
return evDate;
}