Format Date Invariant in string interpolation - CSharp Language Basics

CSharp examples for Language Basics:Data Type Format

Description

Format Date Invariant in string interpolation

Demo Code

using System;//from  w  ww  .  j  a  v a 2 s .  c  o m
using System.ComponentModel;
using System.Globalization;
using static System.FormattableString;
class FormatDateInvariant
{
   static void Main()
   {
      DateTime date = DateTime.UtcNow;
      string parameter1 = string.Format(CultureInfo.InvariantCulture,"x={0:yyyy-MM-dd}",date);
      string parameter2 =((FormattableString)$"x={date:yyyy-MM-dd}").ToString(CultureInfo.InvariantCulture);
      string parameter3 = FormattableString.Invariant($"x={date:yyyy-MM-dd}");
      string parameter4 = Invariant($"x={date:yyyy-MM-dd}");
   }
}

Related Tutorials