当前位置: 首页>>代码示例>>C#>>正文


C# DateTimeOffset.ToString方法代码示例

本文整理汇总了C#中DateTimeOffset.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeOffset.ToString方法的具体用法?C# DateTimeOffset.ToString怎么用?C# DateTimeOffset.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTimeOffset的用法示例。


在下文中一共展示了DateTimeOffset.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FormatStartDate

 public string FormatStartDate(DateTimeOffset startDateTime)
 {
     var timeOfDay = startDateTime.TimeOfDay;
     return timeOfDay.Hours == 0
                 ? startDateTime.ToString(DateOnlyPattern)
                 : startDateTime.ToString(DateAndTimePattern);
 }
开发者ID:philpursglove,项目名称:DDDEastAnglia,代码行数:7,代码来源:DateTimeFormatter.cs

示例2: ToString

        /// <summary>
        /// 定义将时间点对象 <see cref="System.DateTimeOffset"/> 转换为字符串的方法。
        /// </summary>
        /// <param name="datetimeOffset"></param>
        /// <returns></returns>
        protected override string ToString(DateTimeOffset datetimeOffset)
        {
            if (datetimeOffset.HasDate())
                return datetimeOffset.HasTime() ? base.ToString(datetimeOffset) : datetimeOffset.ToString(this.Culture.DateTimeFormat.ShortDatePattern, this.Culture);
            else if (datetimeOffset.HasTime())
                return datetimeOffset.ToString(this.Culture.DateTimeFormat.ShortTimePattern, this.Culture);

            return base.ToString(datetimeOffset);
        }
开发者ID:kylin589,项目名称:NDF.Infrastructure,代码行数:14,代码来源:GeneralDateTimeConverter.cs

示例3: HistoryEntry

 public HistoryEntry(string id, DateTimeOffset timestamp, string operatorName, string alarmStatus, string alarmState, string response)
 {
     Id = id;
     Timestamp = timestamp.ToString("G", CultureInfo.CurrentCulture);
     SortableTimestamp = timestamp.ToString("s", CultureInfo.InvariantCulture);
     OperatorName = operatorName;
     AlarmStatus = alarmStatus;
     AlarmState = alarmState;
     Response = response;
 }
开发者ID:shayaneumar,项目名称:gabbar,代码行数:10,代码来源:HistoryEntry.cs

示例4: Message

 /// <summary>
 /// Creates an immutable message object
 /// </summary>
 /// <param name="id">Message id</param>
 /// <param name="description">Message description</param>
 /// <param name="partitionId">The GUID of the partition the message occurred on</param>
 /// <param name="partitionName">The name of the partition the message occurred on</param>
 /// <param name="isPublic">True if the message is public, otherwise false</param>
 /// <param name="messageDateTime">The Date and Time the message occurred.</param>
 public Message(Guid id, string description, Guid partitionId, string partitionName, bool isPublic, DateTimeOffset messageDateTime)
 {
     Id = id;
     Description = description;
     PartitionId = partitionId;
     PartitionName = partitionName;
     IsPublic = isPublic;
     MessageDateTime = messageDateTime;
     MessageDateString = MessageDateTime.ToString("d", CultureInfo.CurrentCulture);
     MessageTimeString = MessageDateTime.ToString("t", CultureInfo.CurrentCulture);
     MessageDateTimeString = MessageDateTime.ToString("G", CultureInfo.CurrentCulture);
     MessageDateTimeSortableString = MessageDateTime.ToString("s", CultureInfo.InvariantCulture);
     MessageUtcDateTime = (long) (MessageDateTime.UtcDateTime - new DateTime(1970,1,1,0,0,0,0,DateTimeKind.Utc)).TotalMilliseconds;
 }
开发者ID:shayaneumar,项目名称:gabbar,代码行数:23,代码来源:Message.cs

示例5: Case

 /// <summary>
 /// Creates an immutable Case object
 /// </summary>        
 /// <param name="id">Globally unique identifier for the case</param>
 /// <param name="title">Title of the case</param>
 /// <param name="createdBy">User who created the case</param>
 /// <param name="createdDateTime">Time and Date that the case was created</param>
 /// <param name="owner">User who owns the case</param>
 /// <param name="notes">The list of notes on the case</param>
 /// <param name="status">Status of the case</param>
 public Case(string id, string title, string createdBy, DateTimeOffset createdDateTime, string owner, IEnumerable<CaseNote> notes, CaseStatus status)
 {
     Id = id;
     Title = title;
     CreatedBy = createdBy;
     CreatedDateTime = createdDateTime;
     CreatedDateString = CreatedDateTime.ToString("d", CultureInfo.CurrentCulture);
     CreatedTimeString = CreatedDateTime.ToString("t", CultureInfo.CurrentCulture);
     CreatedDateTimeString = CreatedDateTime.ToString("g", CultureInfo.CurrentCulture);
     CreatedDateTimeSortableString = CreatedDateTime.ToString("s", CultureInfo.InvariantCulture);
     Owner = owner;
     Notes = notes.ToList();
     StatusEnum = status;
 }
开发者ID:shayaneumar,项目名称:gabbar,代码行数:24,代码来源:Case.cs

示例6: Between

        /// <summary>
        ///   Determines if the time is in the specified time period.
        /// </summary>
        /// <param name="now">
        ///   The time to compare.
        /// </param>
        /// <param name="inclusiveStart">The inclusive start time.</param>
        /// <param name="exclusiveEnd">The exclusive end time.</param>
        /// <returns>
        ///   <b>true</b> if <paramref name="now"/> within the specified period; otherwise <b>false</b>.
        /// </returns>
        /// <exception cref="ArgumentOutOfRangeException">
        ///   <paramref name="exclusiveEnd"/> must be greater than <paramref name="inclusiveStart"/>.
        /// </exception>
        /// <example>
        ///   <code title="Credit Card Check" source="SepiaExamples\TimeExample.cs" region="Credit Card Check" language="C#" />
        /// </example>
        public static bool Between(this DateTimeOffset now, DateTimeOffset inclusiveStart, DateTimeOffset exclusiveEnd)
        {
            if (exclusiveEnd <= inclusiveStart)
                throw new ArgumentOutOfRangeException("end", exclusiveEnd.ToString("o"), string.Format("The end must be greater than the start '{0:o}'.", inclusiveStart));

            return inclusiveStart <= now && now < exclusiveEnd;
        }
开发者ID:richardschneider,项目名称:sepia,代码行数:24,代码来源:TimeExtensions.cs

示例7: ProcessRequest

        internal void ProcessRequest(ResourceSession rpResourceSession, Session rpSession)
        {
            if (CurrentMode == CacheMode.Disabled)
                return;

            string rFilename;
            var rNoVerification = CheckFileInCache(rpResourceSession.Path, out rFilename);

            rpResourceSession.CacheFilename = rFilename;

            if (rNoVerification == null)
                return;

            if (!rNoVerification.Value)
            {
                var rTimestamp = new DateTimeOffset(File.GetLastWriteTime(rFilename));

                if (rpResourceSession.Path.OICContains("mainD2.swf") || rpResourceSession.Path.OICContains(".js") || !CheckFileVersionAndTimestamp(rpResourceSession, rTimestamp))
                {
                    rpSession.oRequest["If-Modified-Since"] = rTimestamp.ToString("R");
                    rpSession.bBufferResponse = true;

                    return;
                }
            }

            rpSession.utilCreateResponseAndBypassServer();
            LoadFile(rFilename, rpResourceSession, rpSession);
        }
开发者ID:amatukaze,项目名称:IntelligentNavalGun,代码行数:29,代码来源:CacheService.cs

示例8: SerializationTests_DateTimeOffset

        public void SerializationTests_DateTimeOffset()
        {
            // Local Kind
            DateTime inputLocalDateTime = DateTime.Now;
            DateTimeOffset inputLocal = new DateTimeOffset(inputLocalDateTime);

            DateTimeOffset outputLocal = SerializationManager.RoundTripSerializationForTesting(inputLocal);
            Assert.AreEqual(inputLocal, outputLocal, "Local time");
            Assert.AreEqual(
                inputLocal.ToString(CultureInfo.InvariantCulture),
                outputLocal.ToString(CultureInfo.InvariantCulture));
            Assert.AreEqual(inputLocal.DateTime.Kind, outputLocal.DateTime.Kind);

            // UTC Kind
            DateTime inputUtcDateTime = DateTime.UtcNow;
            DateTimeOffset inputUtc = new DateTimeOffset(inputUtcDateTime);

            DateTimeOffset outputUtc = SerializationManager.RoundTripSerializationForTesting(inputUtc);
            Assert.AreEqual(inputUtc, outputUtc, "UTC time");
            Assert.AreEqual(
                inputUtc.ToString(CultureInfo.InvariantCulture),
                outputUtc.ToString(CultureInfo.InvariantCulture));
            Assert.AreEqual(inputUtc.DateTime.Kind, outputUtc.DateTime.Kind);

            // Unspecified Kind
            DateTime inputUnspecifiedDateTime = new DateTime(0x08d27e2c0cc7dfb9);
            DateTimeOffset inputUnspecified = new DateTimeOffset(inputUnspecifiedDateTime);

            DateTimeOffset outputUnspecified = SerializationManager.RoundTripSerializationForTesting(inputUnspecified);
            Assert.AreEqual(inputUnspecified, outputUnspecified, "Unspecified time");
            Assert.AreEqual(
                inputUnspecified.ToString(CultureInfo.InvariantCulture),
                outputUnspecified.ToString(CultureInfo.InvariantCulture));
            Assert.AreEqual(inputUnspecified.DateTime.Kind, outputUnspecified.DateTime.Kind);
        }
开发者ID:REALTOBIZ,项目名称:orleans,代码行数:35,代码来源:SerializationTests.DifferentTypes.cs

示例9: DateTimeOffsetScenarioShouldFail

        public void DateTimeOffsetScenarioShouldFail()
        {
            var date = new DateTimeOffset(new DateTime(2000, 6, 1), TimeSpan.Zero);
            var dateString = date.ToString();
            var exptected = new DateTimeOffset(new DateTime(2000, 6, 1, 1, 0, 1), TimeSpan.Zero);
            var expectedDate = exptected.ToString();
            Verify.ShouldFail(() =>
date.ShouldBe(exptected, TimeSpan.FromHours(1), "Some additional context"),

errorWithSource:
[email protected]"date
    should be within
01:00:00
    of
{expectedDate}
    but was
{dateString}

Additional Info:
    Some additional context",

errorWithoutSource:
[email protected]"{dateString}
    should be within
01:00:00
    of
{expectedDate}
    but was not

Additional Info:
    Some additional context");
        }
开发者ID:CoderDennis,项目名称:shouldly,代码行数:32,代码来源:DateTimeOffsetScenario.cs

示例10: RepositoryInfo

 public RepositoryInfo(Repository repository, DateTimeOffset commitDate, string hash)
 {
     ProjectName = repository.Name;
     ProjectId = repository.Id;
     Date = commitDate.ToString("yyyy-MM-dd");
     Hash = hash;
 }
开发者ID:elpikel,项目名称:Publisher,代码行数:7,代码来源:RepositoryInfo.cs

示例11: ToAtomString

 internal static string ToAtomString(DateTimeOffset dateTime)
 {
     if (dateTime.Offset == zeroOffset)
     {
         return dateTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture);
     }
     return dateTime.ToString("yyyy-MM-ddTHH:mm:sszzz", CultureInfo.InvariantCulture);
 }
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:ODataAtomConvert.cs

示例12: AsString

 private string AsString(DateTimeOffset dateTime)
 {
     if (dateTime.Offset == zeroOffset)
     {
         return dateTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture);
     }
     return dateTime.ToString("yyyy-MM-ddTHH:mm:sszzz", CultureInfo.InvariantCulture);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:Atom10FeedFormatter.cs

示例13: PrintNetworkUsage

        private string PrintNetworkUsage(NetworkUsage networkUsage, DateTimeOffset startTime)
        {
            string result = "Usage from " + startTime.ToString() + " to " + (startTime + networkUsage.ConnectionDuration).ToString() +
                "\n\tBytes sent: " + networkUsage.BytesSent +
                "\n\tBytes received: " + networkUsage.BytesReceived + "\n";

            return result;
        }
开发者ID:mbin,项目名称:Win81App,代码行数:8,代码来源:ProfileLocalUsageData.xaml.cs

示例14: ConvertTo_WithContext

        public static void ConvertTo_WithContext()
        {
            DateTimeFormatInfo formatInfo = (DateTimeFormatInfo)CultureInfo.CurrentCulture.GetFormat(typeof(DateTimeFormatInfo));
            string formatWithTime = formatInfo.ShortDatePattern + " " + formatInfo.ShortTimePattern + " zzz";
            string format = formatInfo.ShortDatePattern + " zzz";
            DateTimeOffset testDateAndTime = new DateTimeOffset(new DateTime(1998, 12, 5, 22, 30, 30));

            ConvertTo_WithContext(new object[5, 3]
                {
                    { DateTimeOffsetConverterTests.s_testOffset, DateTimeOffsetConverterTests.s_testOffset.ToString(format, CultureInfo.CurrentCulture), null },
                    { testDateAndTime, testDateAndTime.ToString(formatWithTime, CultureInfo.CurrentCulture), null },
                    { DateTimeOffset.MinValue, string.Empty, null },
                    { DateTimeOffsetConverterTests.s_testOffset, DateTimeOffsetConverterTests.s_testOffset.ToString("yyyy-MM-dd zzz", CultureInfo.InvariantCulture), CultureInfo.InvariantCulture },
                    { testDateAndTime, testDateAndTime.ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture }
                },
                DateTimeOffsetConverterTests.s_converter);
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:17,代码来源:DateTimeOffsetConverterTests.cs

示例15: PrintNetworkUsage

        private string PrintNetworkUsage(AttributedNetworkUsage networkUsage, DateTimeOffset startTime, DateTimeOffset endTime)
        {
            string result = "Usage by " + networkUsage.AttributionName +
                "\n\tFrom: " + startTime.ToString() + " to " + endTime.ToString() +
                "\n\tBytes sent: " + networkUsage.BytesSent +
                "\n\tBytes received: " + networkUsage.BytesReceived + "\n";

            return result;
        }
开发者ID:trilok567,项目名称:Windows-Phone,代码行数:9,代码来源:Scenario8_attributednetworkusage.xaml.cs


注:本文中的DateTimeOffset.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。