本文整理汇总了C#中DateTimeOffset.ToUniversalTime方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeOffset.ToUniversalTime方法的具体用法?C# DateTimeOffset.ToUniversalTime怎么用?C# DateTimeOffset.ToUniversalTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeOffset
的用法示例。
在下文中一共展示了DateTimeOffset.ToUniversalTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DateTimeOffset_Can_Specifity_Your_Local_Time_From_Utc_Point_Of_View
public void DateTimeOffset_Can_Specifity_Your_Local_Time_From_Utc_Point_Of_View()
{
var jonsTime = new DateTimeOffset(2011, 4, 1, 21, 24, 0, TimeSpan.FromHours(1));
var localTime = new DateTime(2011, 4, 1, 20, 24, 0);
Assert.That(jonsTime.ToUniversalTime().Hour, Is.EqualTo(localTime.Hour));
}
示例2: 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);
}
示例3: 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);
}
示例4: WriteDate
public void WriteDate(DateTimeOffset datetime)
{
this.writeAmf3Type(Amf3Type.Date);
UInt29 remainIndex = 0;
remainIndex.WriteAsRefTo(false,this.writer_);
var utcTime = datetime.ToUniversalTime();
var totalMilliseconds = utcTime.ToUnixTime();
this.writer_.WriteDouble(totalMilliseconds);
}
示例5: ConvertDateTimeValue_NonStandardPrimitives_DefaultTimeZoneInfo
public void ConvertDateTimeValue_NonStandardPrimitives_DefaultTimeZoneInfo(DateTimeOffset valueToConvert)
{
// Arrange & Act
TimeZoneInfoHelper.TimeZone = null;
object actual = EdmPrimitiveHelpers.ConvertPrimitiveValue(valueToConvert, typeof(DateTime));
// Assert
DateTime dt = Assert.IsType<DateTime>(actual);
Assert.Equal(valueToConvert.ToUniversalTime().ToOffset(TimeZoneInfo.Local.BaseUtcOffset).DateTime, dt);
}
示例6: DateTimeOffSet
public void DateTimeOffSet()
{
//System.DateTimeOffset (.NET 2.0SP1 / .NET 3.5)
DateTimeOffset myTime = new DateTimeOffset(2015, 11, 12, 9, 13, 0, TimeSpan.FromHours(1));
Console.WriteLine( myTime);
Console.WriteLine(myTime.ToUniversalTime());
//System.TimeZoneInfo (.NET 3.5)
}
示例7: ConvertDateTimeValue_NonStandardPrimitives_CustomTimeZoneInfo
public void ConvertDateTimeValue_NonStandardPrimitives_CustomTimeZoneInfo(DateTimeOffset valueToConvert)
{
// Arrange & Act
TimeZoneInfoHelper.TimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
object actual = EdmPrimitiveHelpers.ConvertPrimitiveValue(valueToConvert, typeof(DateTime));
// Assert
DateTime dt = Assert.IsType<DateTime>(actual);
Assert.Equal(valueToConvert.ToUniversalTime().ToOffset(new TimeSpan(-8, 0, 0)).DateTime, dt);
}
示例8: AsString
private string AsString(DateTimeOffset dateTime)
{
if (dateTime.Offset == Atom10FeedFormatter.zeroOffset)
{
return dateTime.ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss Z", CultureInfo.InvariantCulture);
}
StringBuilder builder = new StringBuilder(dateTime.ToString("ddd, dd MMM yyyy HH:mm:ss zzz", CultureInfo.InvariantCulture));
builder.Remove(builder.Length - 3, 1);
return builder.ToString();
}
示例9: TIME
public static XElement TIME(string name, DateTimeOffset time)
{
var t1 = time.ToUniversalTime();
var t2 = time.ToLocalTime().ToString("G");
return new XElement(
XN.time,
PROP(name),
new XAttribute(XN.datetime, t1),
t2);
}
示例10: UserList
public UserList(string usersFile, DateTimeOffset startOfWeek)
: this(usersFile)
{
StartOfPeriod = startOfWeek.ToUniversalTime();
EndOfPeriod = StartOfPeriod.AddDays(7);
// We only count events attached to posts (questions or answers) that we created at most 3 days before
// the week starts. The idea is to not keep rewarding users for old entries that are getting upticks
FirstStackOverflowPost = QueryHelpers.GetIdOfFirstPostOfDay(StartOfPeriod.AddDays(-3));
}
示例11: DateTimeOffset
public void DateTimeOffset()
{
// System.DateTimeOffset (.NET 3.5)
DateTimeOffset axelsTime = new DateTimeOffset(2011, 4, 1, 21, 24, 0, TimeSpan.FromHours(1));
//Console.WriteLine(axelsTime);
//Console.WriteLine(axelsTime.ToUniversalTime());
DateTimeOffset robsTime = new DateTimeOffset(2011, 4, 1, 10, 24, 0, TimeSpan.FromHours(-10));
Assert.AreEqual(axelsTime, robsTime);
Assert.AreEqual(axelsTime.ToUniversalTime(), robsTime.ToUniversalTime());
}
示例12: AbsoluteTimer
public WaitHandle AbsoluteTimer(DateTimeOffset expireAt)
{
var handle = CreateWaitableTimer(IntPtr.Zero, true, null);
var dueTime = expireAt.ToUniversalTime().ToFileTime();
SetWaitableTimer(handle, ref dueTime, 0, IntPtr.Zero, IntPtr.Zero, false);
var safeHandle = new SafeWaitHandle(handle, true);
return new TimerWaitHandle(safeHandle);
}
示例13: CopyFromDocument
public void CopyFromDocument()
{
var mapper = CreateMapper();
var doc = new Document();
var ts = new DateTimeOffset(new DateTime(2013, 1, 1));
doc.Add(new Field("TimeStampOffset", ts.ToUniversalTime().Ticks.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
mapper.CopyFromDocument(doc, 0, this);
Assert.That(TimeStampOffset, Is.EqualTo(ts));
}
开发者ID:benjaminramey,项目名称:Lucene.Net.Linq,代码行数:13,代码来源:FieldMappingInfoBuilderNumericDateTimeOffsetTests.cs
示例14: modified
public modified()
{
point_in_time = new DateTimeOffset(2011,09,24,22,00,0,0, 2.Hours());
// last-modified: 24 Sep 2011 23:11:00 +0200 (21:00:00 GMT)
given_resource(
"/resource",
resource=>resource.Map<ResourceWithLastModified>().LastModified(_=> _.LastModified),
new ResourceWithLastModified { LastModified = point_in_time + 1.Hours() });
// if-modified-since: 24 Sep 2011 22:00:00 +0200 (20:00:00 GMT)
given_request_header("if-modified-since", point_in_time.ToUniversalTime().ToString("R"));
when_executing_request("/resource");
}
示例15: DateTimeSerializeToJSON
private string DateTimeSerializeToJSON(DateTime dateTime)
{
var value = new DateTimeOffset(dateTime);
var kind = dateTime.Kind;
var num = ((value.ToUniversalTime().Ticks - new DateTime(0x7b2, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks) / 0x2710L);
var str = string.Empty;
switch (kind)
{
case DateTimeKind.Unspecified:
case DateTimeKind.Local:
TimeSpan offset = value.Offset;
str = offset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture) + offset.Minutes.ToString("00;00", CultureInfo.InvariantCulture);
break;
}
return ("\"\\/Date(" + num.ToString(CultureInfo.InvariantCulture) + str + ")\\/\"");
}