本文整理汇总了C#中System.DateTime.AddHours方法的典型用法代码示例。如果您正苦于以下问题:C# System.DateTime.AddHours方法的具体用法?C# System.DateTime.AddHours怎么用?C# System.DateTime.AddHours使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTime
的用法示例。
在下文中一共展示了System.DateTime.AddHours方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryParseDateTime
public static bool TryParseDateTime(this string s, out System.DateTime result)
{
// implement this using string manipulation
result = new System.DateTime();
// Wed, 07 Oct 2015 23:17:26 GMT
// 0 1 2
// 0123456789012345678901234567890
try
{
int day = int.Parse(s.Substring(5, 2));
int month = System.Array.IndexOf(months, s.Substring(8, 3)) + 1;
int year = int.Parse(s.Substring(12, 4));
int hour = int.Parse(s.Substring(17, 2));
int minute = int.Parse(s.Substring(20, 2));
int second = int.Parse(s.Substring(23, 2));
// create DateTime with these values
// make sure it's UTC
result = new System.DateTime(year, month, day, hour, minute, second, 0).ToUniversalTime();
// we should have a valid DateTime
return true;
}
catch { };
// try with next format
// 10/7/2015 23:17:26 PM
// this one has a nice pattern, split with spaces to get date and time and then split each one to get individual date bits
try
{
string[] splitDateTime = s.Split(' ');
string[] date = splitDateTime[0].Split('/');
string[] time = splitDateTime[1].Split(':');
// create DateTime with these values
// make sure it's UTC
result = new System.DateTime(int.Parse(date[2]), int.Parse(date[0]), int.Parse(date[1]), int.Parse(time[0]), int.Parse(time[1]), int.Parse(time[2])).ToUniversalTime();
// check for PM time and add 12H if required
if (splitDateTime[2] == "PM")
{
result = result.AddHours(12);
}
// we should have a valid DateTime now
return true;
}
catch { };
// no joy parsing this one
return false;
}
示例2: RetrieveLinkerTimestamp
/// <summary>
/// Retrieves the linker timestamp.
/// </summary>
/// <param name="filePath">The file path.</param>
/// <returns></returns>
/// <remarks>http://www.codinghorror.com/blog/2005/04/determining-build-date-the-hard-way.html</remarks>
private static System.DateTime RetrieveLinkerTimestamp(string filePath)
{
const int peHeaderOffset = 60;
const int linkerTimestampOffset = 8;
var b = new byte[2048];
System.IO.FileStream s = null;
try
{
s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
s.Read(b, 0, 2048);
}
finally
{
if (s != null)
s.Close();
}
var dt = new System.DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(System.BitConverter.ToInt32(b, System.BitConverter.ToInt32(b, peHeaderOffset) + linkerTimestampOffset));
return dt.AddHours(System.TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);
}
示例3: Form1
public Form1()
{
InitializeComponent();
_1min = Properties.Settings.Default._1min;
_5min = Properties.Settings.Default._5min;
menuStrip.BackColor = System.Drawing.ColorTranslator.FromHtml("#88ffffff");
horario = System.DateTime.Today;
horario = horario.AddHours(Properties.Settings.Default.Hora); //Utiliza a configuração padrão de hora
horario = horario.AddMinutes(Properties.Settings.Default.Minuto); //Utiliza a configuração padrão de minuto
alterarFontes();
lblRelogio.Text = System.DateTime.Now.ToString("HH:mm");
timer1.Interval = 1000;
timer1.Start();
//Inicializa a localização dos audios
_1minPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\resources\\mp3_1min.mp3";
_5minPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\resources\\mp3_5min.mp3";
if (!System.IO.File.Exists(_1minPath) || !System.IO.File.Exists(_5minPath))
System.Windows.MessageBox.Show("Arquivos de áudio foram deletados ou corrompidos\nReinstale o programa para corrigir.", "Falha ao abrir áudios", System.Windows.MessageBoxButton.OK, MessageBoxImage.Error);
configurarExibicao();
}