本文整理汇总了C#中System.DateTime.AddMilliseconds方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.AddMilliseconds方法的具体用法?C# DateTime.AddMilliseconds怎么用?C# DateTime.AddMilliseconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTime
的用法示例。
在下文中一共展示了DateTime.AddMilliseconds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: read
public IAdaptingType read( FlashorbBinaryReader reader, ParseContext parseContext )
{
double dateTime = reader.ReadDouble();
// ignore the stupid timezone
reader.ReadUnsignedShort();
DateTime sent = new DateTime( 1970, 1, 1 );
#if (FULL_BUILD || PURE_CLIENT_LIB )
// get the offset of the time zone the server is in
double localTimezoneOffset = TimeZone.CurrentTimeZone.GetUtcOffset( sent ).TotalMilliseconds;
// convert 1/1/1970 12AM to UTC
sent = TimeZone.CurrentTimeZone.ToUniversalTime( sent );
#else
double localTimezoneOffset = TimeZoneInfo.Local.GetUtcOffset( sent ).TotalMilliseconds;
sent = TimeZoneInfo.ConvertTime( sent, TimeZoneInfo.Utc );
#endif
// bring it back to 12AM
sent = sent.AddMilliseconds( localTimezoneOffset );
// now that the sent object is in UTC and it represents 1/1/1970 12AM
// convert it to the time sent by the client. The result of the operation
// is going to be client's datetime object in UTC
sent = sent.AddMilliseconds( dateTime );
return new DateType( sent );
}
示例2: Count
public int[] Count(string query, DateTime rangeFrom, DateTime rangeTo, int timeSlices, string groupBy)
{
int[] result = new int[timeSlices];
TimeSpan rangeDuration = rangeTo.Subtract(rangeFrom);
int timeSliceDuration = (int)rangeDuration.TotalMilliseconds / timeSlices;
for (int timeSlice = 0; timeSlice < timeSlices; timeSlice++)
{
EAEPMessages messages = store.GetMessages(
rangeFrom.AddMilliseconds(timeSlice * timeSliceDuration),
rangeFrom.AddMilliseconds((timeSlice + 1) * timeSliceDuration),
query);
if (groupBy != null)
{
HashSet<string> groups = new HashSet<string>();
foreach (EAEPMessage message in messages)
{
if (message.ContainsParameter(groupBy) && !groups.Contains(message[groupBy]))
{
groups.Add(message[groupBy]);
}
}
result[timeSlice] = groups.Count;
}
else
{
result[timeSlice] = messages.Count;
}
}
return result;
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
AccountInfo cu = ServerImpl.Instance.GetCurrentUser(Context);
if (cu == null || !cu.IsAdmin) throw new Exception("你没有权限访问该页面!");
if (IsPostBack)
{
switch (Request.Params["command"])
{
case "Delete":
{
Core.MessageImpl.Instance.DeleteMessages(Request.Params["data"]);
break;
}
}
}
DateTime from, to, baseDate = new DateTime(1900, 1, 1);
from = Request.QueryString["From"] == null ? new DateTime(1900, 1, 1) : baseDate.AddMilliseconds(Convert.ToInt32(Request.QueryString["From"]));
to = Request.QueryString["To"] == null ? new DateTime(2100, 1, 1) : baseDate.AddMilliseconds(Convert.ToInt32(Request.QueryString["To"]));
Int32 pageSize = 15;
Int32 user = Request.QueryString["User"] == null ? 0 : Convert.ToInt32(Request.QueryString["User"]);
Int32 peer = Request.QueryString["Peer"] == null ? 0 : Convert.ToInt32(Request.QueryString["Peer"]);
int msgId = 0;
if (Request.QueryString["CurrentPage"] != null)
{
_currentPage = Convert.ToInt32(Request.QueryString["CurrentPage"]);
msgId = 0;
}
else
{
_currentPage = -1;
msgId = Request.QueryString["MsgID"] == null ? 0 : Convert.ToInt32(Request.QueryString["MsgID"]);
}
Core.MessageImpl.Instance.WriteCache();
DataTable msgs = null;
if (peer > 0) msgs = Core.MessageImpl.Instance.GetUserMessages(user, peer, from, to, pageSize, ref _currentPage, out _pageCount, msgId);
else msgs = Core.MessageImpl.Instance.GetGroupMessages(user, from, to, pageSize, ref _currentPage, out _pageCount, msgId);
foreach (DataRow row in msgs.Rows)
{
Message_MessageCtrl ctrl = LoadControl("MessageCtrl.ascx") as Message_MessageCtrl;
ctrl.Data = row;
FindControl("MsgContainer").Controls.Add(ctrl);
}
}
示例4: TestGetFireTimeAfter
public void TestGetFireTimeAfter()
{
DateTimeOffset startCalendar = new DateTime(2005, 6, 1, 9, 30, 17);
// Test yearly
NthIncludedDayTrigger yearlyTrigger = new NthIncludedDayTrigger();
yearlyTrigger.IntervalType = NthIncludedDayTrigger.IntervalTypeYearly;
yearlyTrigger.StartTimeUtc = startCalendar;
yearlyTrigger.N = 10;
yearlyTrigger.FireAtTime = "14:35:15";
DateTimeOffset targetCalendar = new DateTime(2006, 1, 10, 14, 35, 15).ToUniversalTime();
DateTimeOffset? nextFireTimeUtc;
nextFireTimeUtc = yearlyTrigger.GetFireTimeAfter(startCalendar.AddMilliseconds(1000));
Assert.AreEqual(targetCalendar, nextFireTimeUtc.Value);
// Test monthly
NthIncludedDayTrigger monthlyTrigger = new NthIncludedDayTrigger();
monthlyTrigger.IntervalType = NthIncludedDayTrigger.IntervalTypeMonthly;
monthlyTrigger.StartTimeUtc = startCalendar;
monthlyTrigger.N = 5;
monthlyTrigger.FireAtTime = "14:35:15";
targetCalendar = new DateTime(2005, 6, 5, 14, 35, 15).ToUniversalTime();
nextFireTimeUtc = monthlyTrigger.GetFireTimeAfter(startCalendar.AddMilliseconds(1000));
Assert.AreEqual(targetCalendar, nextFireTimeUtc.Value);
// Test weekly
NthIncludedDayTrigger weeklyTrigger = new NthIncludedDayTrigger();
weeklyTrigger.IntervalType = NthIncludedDayTrigger.IntervalTypeWeekly;
weeklyTrigger.StartTimeUtc = startCalendar;
weeklyTrigger.N = 3;
weeklyTrigger.FireAtTime = "14:35:15";
//roll start date forward to first day of the next week
while (startCalendar.DayOfWeek != DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek)
{
startCalendar = startCalendar.AddDays(1);
}
//calculate expected fire date
targetCalendar = new DateTime(startCalendar.Year, startCalendar.Month, startCalendar.Day, 14, 35, 15);
//first day of the week counts as one. add two more to get N=3.
targetCalendar = targetCalendar.AddDays(2);
nextFireTimeUtc = weeklyTrigger.GetFireTimeAfter(startCalendar.AddMilliseconds(1000));
Assert.AreEqual(targetCalendar.ToUniversalTime(), nextFireTimeUtc.Value);
}
示例5: SetSpeed
/// <summary>
/// Set the desired speed of the wheel, and the time to take to get there (ease-in).
/// If time is zero, the specified speed will be set on the next update.
/// If time is non-zero, the speed will be reached in the specified time with a simple linear accelleration.
/// </summary>
/// <remarks>No changes are actually applied to the wheel until <see cref="update"/> is called.</remarks>
/// <param name="speed">Target speed</param>
/// <param name="time">Time to reach speed (millis)</param>
public void SetSpeed(int speed, ulong time = 0)
{
SpeedRequestedAt = DateTime.Now;
SpeedRequestedFor = SpeedRequestedAt.AddMilliseconds(time);
RequestedStartSpeed = CurrentSpeed;
RequestedTargetSpeed = Tools.Constrain(speed, -100, 100);
}
示例6: ToDateTime
public static DateTime ToDateTime(long ticks)
{
DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
DateTime dateTime = start.AddMilliseconds(ticks).ToLocalTime();
return dateTime;
}
示例7: UnixTimeStampToDateTime
public static DateTime UnixTimeStampToDateTime(long unixTimeStamp)
{
// Unix timestamp is seconds past epoch
System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dtDateTime = dtDateTime.AddMilliseconds(unixTimeStamp).ToLocalTime();
return dtDateTime;
}
示例8: IncrementDate
public static DateTime IncrementDate(this TimePeriod period, DateTime date, int amount)
{
switch (period) {
case TimePeriod.Millisecond:
return date.AddMilliseconds(amount);
case TimePeriod.Second:
return date.AddSeconds(amount);
case TimePeriod.Minute:
return date.AddMinutes(amount);
case TimePeriod.Hour:
return date.AddHours(amount);
case TimePeriod.Day:
return date.AddDays(amount);
case TimePeriod.Month:
return date.AddMonths(amount);
case TimePeriod.Quarter:
return date.AddMonths(amount * 3);
case TimePeriod.Half:
return date.AddMonths(amount * 6);
case TimePeriod.Year:
return date.AddYears(amount);
default:
throw new Exception("Unknown period: " + period.ToString());
}
}
示例9: Convert
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
return "";
double milliSecs = 0;
if (!double.TryParse(value.ToString(), System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out milliSecs))
return "";
//unix epoch, UTC (also known as GMT)
System.DateTime date = new System.DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
//add the specified milliseconds
date = date.AddMilliseconds(milliSecs);
//time stamp is UTC (also known as GMT) -> convert to local time zone
date = TimeZoneInfo.ConvertTime(date, TimeZoneInfo.Local);
//return a culture-specific formatted date
// Get the format string for the current UI culture
string dateFormatString = CultureInfo.CurrentUICulture.DateTimeFormat.FullDateTimePattern;
// Remove day and seconds from format string
dateFormatString = Util.RemoveDayFormat(dateFormatString);
dateFormatString = dateFormatString.Replace(":ss", "");
// Replace two digit day with single digit
dateFormatString = dateFormatString.Replace("dd", "d");
// Trim leading and trailing whitespace
dateFormatString = dateFormatString.Trim();
return date.ToString(dateFormatString, CultureInfo.CurrentUICulture);
}
示例10: UnixTimeConverter
public static DateTime UnixTimeConverter(double unx)
{
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
dateTime = dateTime.AddMilliseconds(unx).ToLocalTime();
return dateTime;
}
示例11: convertUnixTimeStampToDateTime
private static DateTime convertUnixTimeStampToDateTime(double unixTimeStamp)
{
// Unix timestamp is seconds past epoch
System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
dtDateTime = dtDateTime.AddMilliseconds(unixTimeStamp).ToLocalTime();
return dtDateTime;
}
示例12: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
double microseconds = (long)reader.Value / 1000.0;
DateTime dateTime = new DateTime(1970, 1, 1);
return dateTime.AddMilliseconds(microseconds);
}
示例13: Check
public override NodeResult Check()
{
DateTime end;
nextUpdate = DateTime.Now;
nextUpdate = nextUpdate.AddMilliseconds(1000 - nextUpdate.Millisecond);
if (timeout.Value == TimeSpan.MaxValue)
end = DateTime.MaxValue;
else
end = DateTime.Now + timeout.Value;
while (true)
{
DateTime now = DateTime.Now;
if (now < nextUpdate)
{
Thread.Sleep(500);
continue;
}
if (now > end)
return NodeResult.Skip;
if (year.Value.Check(nextUpdate.Year) && month.Value.Check(nextUpdate.Month) && day.Value.Check(nextUpdate.Day) && hour.Value.Check(nextUpdate.Hour) && minute.Value.Check(nextUpdate.Minute) && second.Value.Check(nextUpdate.Second))
return NodeResult.Success;
nextUpdate = nextUpdate.AddSeconds(1);
}
}
示例14: FromUnixTimeStamp
private static DateTime FromUnixTimeStamp(ulong unixTimeStamp)
{
DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
dtDateTime = dtDateTime.AddMilliseconds(unixTimeStamp).ToLocalTime();
return dtDateTime;
}
示例15: ExtractDate
private static DateTime ExtractDate( string input, string pattern, CultureInfo culture )
{
DateTime dt = DateTime.MinValue;
var regex = new Regex( pattern );
if ( regex.IsMatch( input ) )
{
var matches = regex.Matches( input );
var match = matches[0];
var ms = Convert.ToInt64( match.Groups[1].Value );
var epoch = new DateTime( 1970, 1, 1, 0, 0, 0, DateTimeKind.Utc );
dt = epoch.AddMilliseconds( ms );
// adjust if time zone modifier present
if ( match.Groups.Count > 2 && !String.IsNullOrEmpty( match.Groups[3].Value ) )
{
var mod = DateTime.ParseExact( match.Groups[3].Value, "HHmm", culture );
if ( match.Groups[2].Value == "+" )
{
dt = dt.Add( mod.TimeOfDay );
}
else
{
dt = dt.Subtract( mod.TimeOfDay );
}
}
}
return dt;
}