LoginSignup
4
2

More than 5 years have passed since last update.

Xamarin.iOS で NSDate を DateTime に変換する

Last updated at Posted at 2016-11-01

なんで NSDate ってこんなにわけわからんの?
こんなもの System.DateTime に変換してやる、えーい!

using System;
using Foundation;

namespace YourNameSpace
{
    public static class NSDateExtensions
    {
        public static DateTime ToDateTime(this NSDate date)
        {
            DateTime reference = TimeZone.CurrentTimeZone.ToLocalTime(
                new DateTime(2001, 1, 1, 0, 0, 0));
            return reference.AddSeconds(date.SecondsSinceReferenceDate);
        }
    }
}

参考は↓だけど、使いやすいように Extension Method にしました。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2