public void ToString_Utc()
        {
            LocalDateTime  local = new LocalDateTime(2012, 10, 6, 1, 2, 3);
            OffsetDateTime odt   = new OffsetDateTime(local, Offset.Zero);

            Assert.AreEqual("2012-10-06T01:02:03Z", odt.ToString());
        }
        public void ToString_WithFormat()
        {
            LocalDateTime  local  = new LocalDateTime(2012, 10, 6, 1, 2, 3);
            Offset         offset = Offset.FromHours(1);
            OffsetDateTime odt    = new OffsetDateTime(local, offset);

            Assert.AreEqual("2012/10/06 01:02:03 01", odt.ToString("yyyy/MM/dd HH:mm:ss o<-HH>", CultureInfo.InvariantCulture));
        }
        public void ToString_WholeHourOffset()
        {
            LocalDateTime  local  = new LocalDateTime(2012, 10, 6, 1, 2, 3);
            Offset         offset = Offset.FromHours(1);
            OffsetDateTime odt    = new OffsetDateTime(local, offset);

            Assert.AreEqual("2012-10-06T01:02:03+01", odt.ToString());
        }
        public void ToString_PartHourOffset()
        {
            LocalDateTime  local  = new LocalDateTime(2012, 10, 6, 1, 2, 3);
            Offset         offset = Offset.FromHoursAndMinutes(1, 30);
            OffsetDateTime odt    = new OffsetDateTime(local, offset);

            Assert.AreEqual("2012-10-06T01:02:03+01:30", odt.ToString());
        }
        public void localdatetime_to_offset() {
            var localDateTime = new LocalDateTime(2016, 1, 21, 20, 6).WithOffset(Offset.FromHours(-5));
            //var tz = DateTimeZoneProviders.Tzdb["America/New_York"];
            var sourceOffsetDateTime = new OffsetDateTime(new LocalDateTime(2016, 1, 21, 20, 6), Offset.FromHours(-5));
            var targetOffset = Offset.FromHours(-10);
            var targetDateTime = sourceOffsetDateTime.WithOffset(targetOffset);

            Assert.Equal("2016-01-21T20:06:00-05", sourceOffsetDateTime.ToString());
            Assert.Equal("2016-01-21T15:06:00-10", targetDateTime.ToString());
        }
        public void localdatetime_to_offset()
        {
            var localDateTime = new LocalDateTime(2016, 1, 21, 20, 6).WithOffset(Offset.FromHours(-5));
            //var tz = DateTimeZoneProviders.Tzdb["America/New_York"];
            var sourceOffsetDateTime = new OffsetDateTime(new LocalDateTime(2016, 1, 21, 20, 6), Offset.FromHours(-5));
            var targetOffset         = Offset.FromHours(-10);
            var targetDateTime       = sourceOffsetDateTime.WithOffset(targetOffset);

            Assert.Equal("2016-01-21T20:06:00-05", sourceOffsetDateTime.ToString());
            Assert.Equal("2016-01-21T15:06:00-10", targetDateTime.ToString());
        }
 public ActionResult <string> Echo(
     [FromQuery, ModelBinder(typeof(OffsetDateTimeBinder))] OffsetDateTime time)
 {
     return(time.ToString());
 }
Beispiel #8
0
 public static string ToIdString(this OffsetDateTime dt)
 {
     return(dt.ToString("uuuu'-'MM'-'dd' T'HH''mm''o<G>", null));
 }
Beispiel #9
0
 public static string ToUserString(this OffsetDateTime dt)
 {
     // ToDo: Change to users local time
     return(dt.ToString("uuuu'-'MM'-'dd' T'HH''mm''o<G>", null));
 }
 public void ToString_WithFormat()
 {
     LocalDateTime local = new LocalDateTime(2012, 10, 6, 1, 2, 3);
     Offset offset = Offset.FromHours(1);
     OffsetDateTime odt = new OffsetDateTime(local, offset);
     Assert.AreEqual("2012/10/06 01:02:03 01", odt.ToString("yyyy/MM/dd HH:mm:ss o<-HH>", CultureInfo.InvariantCulture));
 }
 public void ToString_Utc()
 {
     LocalDateTime local = new LocalDateTime(2012, 10, 6, 1, 2, 3);
     OffsetDateTime odt = new OffsetDateTime(local, Offset.Zero);
     Assert.AreEqual("2012-10-06T01:02:03Z", odt.ToString());
 }
 public void ToString_PartHourOffset()
 {
     LocalDateTime local = new LocalDateTime(2012, 10, 6, 1, 2, 3);
     Offset offset = Offset.FromHoursAndMinutes(1, 30);
     OffsetDateTime odt = new OffsetDateTime(local, offset);
     Assert.AreEqual("2012-10-06T01:02:03+01:30", odt.ToString());
 }
 public void ToString_WholeHourOffset()
 {
     LocalDateTime local = new LocalDateTime(2012, 10, 6, 1, 2, 3);
     Offset offset = Offset.FromHours(1);
     OffsetDateTime odt = new OffsetDateTime(local, offset);
     Assert.AreEqual("2012-10-06T01:02:03+01", odt.ToString());
 }
Beispiel #14
0
 public static string Serialize(this OffsetDateTime x) =>
 x.ToString("r", CultureInfo.InvariantCulture);
Beispiel #15
0
 /// <summary>
 /// Serializes the <see cref="OffsetDateTime"/> for SQL Server queries and wraps it in single quotes.
 /// </summary>
 /// <param name="offsetDateTime">An offset date time.</param>
 /// <returns>A SQL formatted string representation of <paramref name="offsetDateTime"/> wrapped in single quotes.</returns>
 /// <seealso cref="ToSqlString"/>
 public static string ToQuotedSqlString(this OffsetDateTime offsetDateTime) => offsetDateTime.ToString(@"yyyy'-'MM'-'dd HH':'mm':'ss.FFFFFFFo<m>", CultureInfo.InvariantCulture);