本文整理汇总了C#中System.DateTime.ToUniversalTime方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.ToUniversalTime方法的具体用法?C# DateTime.ToUniversalTime怎么用?C# DateTime.ToUniversalTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTime
的用法示例。
在下文中一共展示了DateTime.ToUniversalTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DelayedUntil
public Respond DelayedUntil(DateTime time)
{
alter = (_, e) => e.ExecutionTime = time.ToUniversalTime();
_description += "; Delayed until " + time.ToUniversalTime();
return this;
}
示例2: Nonce
internal Nonce(DateTime creation, string uniqueFragment, bool remoteServerOrigin)
{
Code = creation.ToUniversalTime().ToString(PermissibleDateTimeFormats[0], CultureInfo.InvariantCulture) + uniqueFragment;
CreationDate = creation.ToUniversalTime();
UniqueFragment = uniqueFragment;
this.remoteServerOrigin = remoteServerOrigin;
}
示例3: MessageEntity
public MessageEntity(DateTime dateTime, string userName, string message)
{
this.PartitionKey = MessagePartionKey;
this.RowKey = Convert.ToString(dateTime.ToUniversalTime().Ticks);
this.dateTime = dateTime;
this.ticks = dateTime.ToUniversalTime().Ticks;
this.userName = userName;
this.message = message;
}
示例4: Write
private static void Write(DateTime timestamp, string message, string category, bool newLine)
{
using (StreamWriter writer = GetWriter())
{
if (newLine)
{
writer.WriteLine();
writer.Write(string.Format("{0} {1} : {2}", timestamp.ToUniversalTime(), category, message));
}
else
writer.Write(string.Format("{0} {1} : {2}", timestamp.ToUniversalTime(), category, message));
}
}
示例5: FromDateTime
// RFC3280, section 4.2.1.5
// CAs conforming to this profile MUST always encode certificate
// validity dates through the year 2049 as UTCTime; certificate validity
// dates in 2050 or later MUST be encoded as GeneralizedTime.
// Under 1.x this API requires a Local datetime to be provided
// Under 2.0 it will also accept a Utc datetime
static public ASN1 FromDateTime (DateTime dt)
{
if (dt.Year < 2050) {
// UTCTIME
return new ASN1 (0x17, Encoding.ASCII.GetBytes (
dt.ToUniversalTime ().ToString ("yyMMddHHmmss",
CultureInfo.InvariantCulture) + "Z"));
}
else {
// GENERALIZEDTIME
return new ASN1 (0x18, Encoding.ASCII.GetBytes (
dt.ToUniversalTime ().ToString ("yyyyMMddHHmmss",
CultureInfo.InvariantCulture) + "Z"));
}
}
示例6: ToInt64
public static long ToInt64(DateTime dateTime)
{
if (dateTime.Kind != DateTimeKind.Utc)
dateTime = dateTime.ToUniversalTime();
return (long)dateTime.Subtract(Epoch).TotalSeconds;
}
示例7: UnixTicks
/// <summary>
/// Datetime转Json时间,datetime - 1970.1.1
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static int UnixTicks(DateTime dt)
{
DateTime d1 = new DateTime(1970, 1, 1);
DateTime d2 = dt.ToUniversalTime();
TimeSpan ts = new TimeSpan(d2.Ticks - d1.Ticks);
return (int)ts.TotalSeconds;
}
示例8: ConvertToUnixTimestamp
public static double ConvertToUnixTimestamp(DateTime date)
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
TimeSpan diff = date.ToUniversalTime() - origin;
return Math.Round(Math.Floor(diff.TotalSeconds), 0);
}
示例9: ToInt32
public static int ToInt32(DateTime dateTime)
{
if (dateTime.Kind != DateTimeKind.Utc)
dateTime = dateTime.ToUniversalTime();
return (int)dateTime.Subtract(Epoch).TotalSeconds;
}
示例10: GetModifiedSearchDocuments
public override IList<SearchDocument> GetModifiedSearchDocuments (ModuleInfo modInfo, DateTime beginDate)
{
var searchDocs = new List<SearchDocument> ();
var settings = new DivisionSettingsRepository ().GetSettings (modInfo);
using (var modelContext = new UniversityModelContext ()) {
var division = modelContext.Get<DivisionInfo> (settings.DivisionID);
if (division != null && division.LastModifiedOnDate.ToUniversalTime () > beginDate.ToUniversalTime ()) {
var aboutDivision = division.SearchDocumentText;
var sd = new SearchDocument ()
{
PortalId = modInfo.PortalID,
AuthorUserId = division.LastModifiedByUserID,
Title = division.Title,
// Description = HtmlUtils.Shorten (aboutDivision, 255, "..."),
Body = aboutDivision,
ModifiedTimeUtc = division.LastModifiedOnDate.ToUniversalTime (),
UniqueKey = string.Format ("University_Division_{0}", division.DivisionID),
Url = string.Format ("/Default.aspx?tabid={0}#{1}", modInfo.TabID, modInfo.ModuleID),
IsActive = division.IsPublished (DateTime.Now)
};
searchDocs.Add (sd);
}
return searchDocs;
}
}
示例11: SetData
public void SetData(byte[] data, int index, int count)
{
using (MemoryStream stream = new MemoryStream(data, index, count, false))
{
using (ZipHelperStream stream2 = new ZipHelperStream(stream))
{
this._flags = (Flags) ((byte) stream2.ReadByte());
if ((((byte) (this._flags & Flags.ModificationTime)) != 0) && (count >= 5))
{
int seconds = stream2.ReadLEInt();
DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0);
this._modificationTime = (time.ToUniversalTime() + new TimeSpan(0, 0, 0, seconds, 0)).ToLocalTime();
}
if (((byte) (this._flags & Flags.AccessTime)) != 0)
{
int num2 = stream2.ReadLEInt();
DateTime time3 = new DateTime(0x7b2, 1, 1, 0, 0, 0);
this._lastAccessTime = (time3.ToUniversalTime() + new TimeSpan(0, 0, 0, num2, 0)).ToLocalTime();
}
if (((byte) (this._flags & Flags.CreateTime)) != 0)
{
int num3 = stream2.ReadLEInt();
DateTime time5 = new DateTime(0x7b2, 1, 1, 0, 0, 0);
this._createTime = (time5.ToUniversalTime() + new TimeSpan(0, 0, 0, num3, 0)).ToLocalTime();
}
}
}
}
示例12: ClearLog
/// <summary>
/// Clears log messages between a date range and for specified log levels
/// </summary>
/// <param name="start">start date</param>
/// <param name="end">end date</param>
/// <param name="logLevels">string array of log levels</param>
public void ClearLog(DateTime start, DateTime end, string[] logLevels)
{
string logLevelList = "";
foreach (string logLevel in logLevels)
{
logLevelList += ",'" + logLevel + "'";
}
if (logLevelList.Length > 0)
{
logLevelList = logLevelList.Substring(1);
}
string commandText = "delete from Log4Net_Error WHERE [Date] >= @p0 and [Date] <= @p1 and Level in (@p2)";
SqlParameter paramStartDate = new SqlParameter { ParameterName = "p0", Value = start.ToUniversalTime(), DbType = System.Data.DbType.DateTime };
SqlParameter paramEndDate = new SqlParameter { ParameterName = "p1", Value = end.ToUniversalTime(), DbType = System.Data.DbType.DateTime };
SqlParameter paramLogLevelList = new SqlParameter { ParameterName = "p2", Value = logLevelList };
//_context.ExecuteStoreCommand(commandText, paramStartDate, paramEndDate, paramLogLevelList);
//required because this code (from http://dotnetdarren.wordpress.com/2010/07/29/logging-in-mvc-part-5-the-model-and-data-layer/)
// was created with an older version of EF, where an objectcontext was used rather than a DBContext (which was created by EF)
var adapter = (IObjectContextAdapter)_context;
var objectContext = adapter.ObjectContext;
objectContext.ExecuteStoreCommand(commandText, paramStartDate, paramEndDate, paramLogLevelList);
}
示例13: Event
protected Event(DateTime dateTime, Galaxy galaxy)
{
Time = dateTime.ToUniversalTime();
Galaxy = galaxy;
Turn = galaxy.Turn;
Round = galaxy.Round;
}
示例14: EST
private void EST (TimeZone t1)
{
// It could be EST though...
//Assert.AreEqual("Eastern Standard Time", t1.StandardName, "B01");
//Assert.AreEqual("Eastern Daylight Time", t1.DaylightName, "B02");
DaylightTime d1 = t1.GetDaylightChanges (2002);
Assert.AreEqual("04/07/2002 02:00:00", d1.Start.ToString ("G", CultureInfo.InvariantCulture), "B03");
Assert.AreEqual("10/27/2002 02:00:00", d1.End.ToString ("G", CultureInfo.InvariantCulture), "B04");
Assert.AreEqual(36000000000L, d1.Delta.Ticks, "B05");
DaylightTime d2 = t1.GetDaylightChanges (1996);
Assert.AreEqual("04/07/1996 02:00:00", d2.Start.ToString ("G", CultureInfo.InvariantCulture), "B06");
Assert.AreEqual("10/27/1996 02:00:00", d2.End.ToString ("G", CultureInfo.InvariantCulture), "B07");
Assert.AreEqual(36000000000L, d2.Delta.Ticks, "B08");
DateTime d3 = new DateTime (2002,2,25);
Assert.AreEqual(false, t1.IsDaylightSavingTime (d3), "B09");
DateTime d4 = new DateTime (2002,4,8);
Assert.AreEqual(true, t1.IsDaylightSavingTime (d4), "B10");
DateTime d5 = new DateTime (2002,11,4);
Assert.AreEqual(false, t1.IsDaylightSavingTime (d5), "B11");
Assert.AreEqual(-180000000000L, t1.GetUtcOffset (d3).Ticks, "B12");
Assert.AreEqual(-144000000000L, t1.GetUtcOffset (d4).Ticks, "B13");
Assert.AreEqual(-180000000000L, t1.GetUtcOffset (d5).Ticks, "B14");
// Test TimeZone methods with UTC DateTime in DST.
DateTime d6 = d4.ToUniversalTime ();
Assert.AreEqual(false, t1.IsDaylightSavingTime (d6), "B15");
Assert.AreEqual(0, t1.GetUtcOffset (d6).Ticks, "B16");
}
示例15: AddAppointment
//android.permission.WRITE_CALENDAR
public void AddAppointment(DateTime startTime, DateTime endTime, String subject, String location, String details, Boolean isAllDay, AppointmentReminder reminder, AppointmentStatus status)
{
ContentValues eventValues = new ContentValues();
eventValues.Put(CalendarContract.Events.InterfaceConsts.CalendarId, 1);
//_calId);
eventValues.Put(CalendarContract.Events.InterfaceConsts.Title, subject);
eventValues.Put(CalendarContract.Events.InterfaceConsts.Description, details);
eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtstart, startTime.ToUniversalTime().ToString());
// GetDateTimeMS(2011, 12, 15, 10, 0));
eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtend, endTime.ToUniversalTime().ToString());
// GetDateTimeMS(2011, 12, 15, 11, 0));
eventValues.Put(CalendarContract.Events.InterfaceConsts.EventTimezone, "UTC");
eventValues.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone, "UTC");
eventValues.Put(CalendarContract.Events.InterfaceConsts.Availability, ConvertAppointmentStatus(status));
eventValues.Put(CalendarContract.Events.InterfaceConsts.EventLocation, location);
eventValues.Put(CalendarContract.Events.InterfaceConsts.AllDay, (isAllDay) ? "1" : "0");
eventValues.Put(CalendarContract.Events.InterfaceConsts.HasAlarm, "1");
var eventUri = CalendarConnector.Activity.ContentResolver.Insert(CalendarContract.Events.ContentUri, eventValues);
long eventID = long.Parse(eventUri.LastPathSegment);
ContentValues remindervalues = new ContentValues();
remindervalues.Put(CalendarContract.Reminders.InterfaceConsts.Minutes, ConvertReminder(reminder));
remindervalues.Put(CalendarContract.Reminders.InterfaceConsts.EventId, eventID);
remindervalues.Put(CalendarContract.Reminders.InterfaceConsts.Method, (int)RemindersMethod.Alert);
var reminderURI = CalendarConnector.Activity.ContentResolver.Insert(CalendarContract.Reminders.ContentUri, remindervalues);
}