NSDate と DateTime の相互変換
- 実際にはもうちょっとタイムゾーンとか色々気を使う必要あるけどざっくりまとめ
- https://forums.xamarin.com/discussion/27184/convert-nsdate-to-datetime
NSDate => DateTime
ReferenceDate ってなんなの...(https://developer.apple.com/documentation/foundation/nsdate)
public static class FoundationExtensions
{
public static DateTime ToDateTime(this NSDate date)
{
// ref: https://developer.apple.com/documentation/foundation/nsdate
var referenceDate = new DateTime(2001, 1, 1);
return referenceDate.AddSeconds(date.SecondsSinceReferenceDate);
}
}
public static NSDate ToNSDate(this DateTime dateTime)
{
var universalTime = dateTime.ToUniversalTime();
var date = NSDate.FromTimeIntervalSinceReferenceDate((universalTime - referenceDate).TotalSeconds);
return date;
}
Pinned Articles
About
ウェブ界隈でエンジニアとして労働活動に励んでいる @gomi_ningen 個人のブログです
Tags
LLM
promptfoo
GenAI
JavaScript
PowerShell
fluentd
kibana
elasticsearch
nginx
村川梨衣
五十嵐裕美
イベント
logrotate
IoT
Scala
Java
ICMP
iputils
C言語
WUG
mastodon
Swift
AWS
Windows
Clock
PoEAA
アーキテクチャ
iOS
DeviceFarm
プログラミング言語
OS
StepFunctions
Lambda
Serverless
terraform
ポエム
RHEL
ネットワーク
GraphQL
CloudWatch
Linux
Coreutils
nc
network
telnet
LinuxKernel
fpinscala
ELB
IAM
AppSync