Last active
October 25, 2016 22:46
-
-
Save drphrozen/4e1a2c8e873e8bee68f9d7a4066524e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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