Skip to content

Instantly share code, notes, and snippets.

View justinsaraceno's full-sized avatar

Justin Saraceno justinsaraceno

View GitHub Profile
@justinsaraceno
justinsaraceno / EncodeTests.cs
Created March 23, 2018 18:55
HTML Encode vs URL Encode
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace EncodingTests
{
[TestClass]
public class EncodeTests
{
[TestMethod]
public void HtmlTags_WhenHtmlEncoded_WillReturnHTMLEncodedOutput()
{
@justinsaraceno
justinsaraceno / nadatimeUTCConvert.cs
Last active January 24, 2024 22:23
Convert UTC DateTime to a specified time zone using Noda Time
// the time zone to convert to
var timeZone = DateTimeZoneProviders.Tzdb["US/Eastern"];
// the date as UTC - this could be from a data store
var fakeUtcDate = new DateTime(2015, 11, 01, 07, 30, 00);
// convert to instant from UTC - see http://stackoverflow.com/questions/20807799/using-nodatime-how-to-convert-an-instant-to-the-corresponding-systems-zoneddat
var instant = Instant.FromDateTimeUtc(DateTime.SpecifyKind(fakeUtcDate, DateTimeKind.Utc));
var result = instant.InZone(timeZone).ToDateTimeUnspecified();