Files
cefsharp/CefSharp/Internals/DateTimeUtils.cs
T
2018-03-06 12:23:18 +10:00

50 lines
1.6 KiB
C#

// Copyright © 2010-2017 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System;
namespace CefSharp.Internals
{
/// <summary>
/// Mapping to/from CefTime
/// </summary>
public static class DateTimeUtils
{
private static DateTime FirstOfTheFirstNineteenSeventy = new DateTime(1970, 1, 1, 0, 0, 0);
/// <summary>
/// Converts a cef
/// </summary>
/// <param name="year">year</param>
/// <param name="month">month</param>
/// <param name="day">day</param>
/// <param name="hour">hour</param>
/// <param name="minute">minute</param>
/// <param name="second">second</param>
/// <param name="millisecond">millisecond</param>
/// <returns>DateTime</returns>
public static DateTime FromCefTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
{
try
{
return new DateTime(year, month, day, hour, minute, second, millisecond);
}
catch(Exception)
{
return DateTime.MinValue;
}
}
/// <summary>
/// Returns epoch (different from 01/01/1970)
/// </summary>
/// <param name="dateTime">datetime</param>
/// <returns>epoch</returns>
public static double ToCefTime(DateTime dateTime)
{
var timeSpan = dateTime - FirstOfTheFirstNineteenSeventy;
return timeSpan.TotalSeconds;
}
}
}