Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

FAQ | Preferences

James Montemagno edited this page Apr 24, 2018 · 4 revisions

Here are frequently asked questions about Preferences:

Is it possible to save DateTime values?

Since each platform does not handle this natively there is no direct API in Preferences to do get and set DateTime. However, you can simply save the Ticks of the DateTime (recommended to use the Universal Time) as a long:

const string MyKey = "dt_key";

public DateTime SavedDateTime
{
    get => new DateTime(Preferences.Get(MyKey, DateTime.UtcNow.Ticks, DateTimeKind.Utc)); 
    set => Preferences.Set(MyKey, value.ToUniversalTime().Ticks); 
}
Clone this wiki locally