コメント
コメントの投稿
※名前とタイトルが入力されていないコメントでは他のコメントとの区別ができません。
入力されていないコメントには返信しませんのであらかじめご了承くださいませ。
using System;
using System.Collections.Generic;
using System.Text;
using Foundation;
namespace AppName.iOS.Extensions
{
public static class DateTimeExtensions
{
/// <summary>
/// System.DateTime から NSDate に変換します。
/// </summary>
/// <returns>The time to native date.</returns>
/// <param name="date">Date.</param>
public static NSDate DateTimeToNSDate(this DateTime date)
{
DateTime reference = TimeZone.CurrentTimeZone.ToLocalTime(
new DateTime(2001, 1, 1, 0, 0, 0));
return NSDate.FromTimeIntervalSinceReferenceDate(
(date - reference).TotalSeconds);
}
/// <summary>
/// NSDate から System.DateTime に変換します。
/// </summary>
/// <returns>The date to date time.</returns>
/// <param name="date">Date.</param>
public static DateTime NSDateToDateTime(this NSDate date)
{
DateTime reference = TimeZone.CurrentTimeZone.ToLocalTime(
new DateTime(2001, 1, 1, 0, 0, 0));
return reference.AddSeconds(date.SecondsSinceReferenceDate);
}
}
}
using AppName.iOS.Extensions;
public class TestCode()
{
private void Test()
{
NSDate dt1 = DateTime.Now.DateTimeToNSDate();
DateTime dt2 = NSDate.Now.NSDateToDateTime();
}
}
※名前とタイトルが入力されていないコメントでは他のコメントとの区別ができません。
入力されていないコメントには返信しませんのであらかじめご了承くださいませ。