Files
cefsharp/CefSharp/Internals/DateTimeUtils.cs
Chris bef5dd37c4 Maintenance - Fixed formatting, file encoding, and copyright year (#2504)
* Applied formatting

* Fixed file encoding + Updated copyright year

* Updated License

* Fixed more file encoding

* Copyright notice now shows the year the file was created
2018-09-10 10:41:13 +10:00

51 lines
1.6 KiB
C#

// Copyright © 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;
}
}
}