public static void WriteDateTime(Utf8JsonWriter writer, DateTime value) { long unixTime = Convert.ToInt64((value.ToUniversalTime() - s_Epoch).TotalMilliseconds); int stackSize = 64; while (true) { Span <byte> span = stackSize <= 1024 ? stackalloc byte[stackSize] : new byte[stackSize]; if (!Utf8Formatter.TryFormat(unixTime, span.Slice(7), out int bytesWritten, new StandardFormat('D'))) { stackSize *= 2; continue; } Start.CopyTo(span); End.CopyTo(span.Slice(7 + bytesWritten)); writer.WriteStringValue( CreateJsonEncodedTextFunc(span.Slice(0, 10 + bytesWritten).ToArray())); break; } }