Skip to content

Instantly share code, notes, and snippets.

@drphrozen
Last active October 25, 2016 22:46
Show Gist options
  • Save drphrozen/4e1a2c8e873e8bee68f9d7a4066524e3 to your computer and use it in GitHub Desktop.
Save drphrozen/4e1a2c8e873e8bee68f9d7a4066524e3 to your computer and use it in GitHub Desktop.
public static class Base64DateTimeHelpers
{
public static string ToBase64(this DateTimeOffset dateTimeOffset)
{
var seconds = dateTimeOffset.ToUnixTimeSeconds();
var buffer = BitConverter.GetBytes(seconds);
return Convert.ToBase64String(buffer);
}
public static string ToBase64UrlSafe(this DateTimeOffset dateTimeOffset)
{
return dateTimeOffset.ToBase64().Replace('+', '-').Replace('/', '_').TrimEnd('=');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment