本文整理汇总了C#中System.DateTime.IsDaylightSavingTime方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.IsDaylightSavingTime方法的具体用法?C# DateTime.IsDaylightSavingTime怎么用?C# DateTime.IsDaylightSavingTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTime
的用法示例。
在下文中一共展示了DateTime.IsDaylightSavingTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getSeason
public static int getSeason(DateTime date)
{
int summer=date.IsDaylightSavingTime() ? 1 : 0;
int season=date.Year * 2;
if (date.IsDaylightSavingTime()) {
season++;
} else if (date.Month>6) {
season += 2;
}
return season;
}
示例2: Convert
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return null;
}
Version v = value as Version;
if (v == null)
{
throw new ArgumentException("Input value must be a Version object (it is a " + value.GetType().FullName + ")", "value");
}
if (v.Build != 0)
{
var time = new DateTime(2000, 1, 1).AddDays(v.Build).AddSeconds(v.Revision * 2);
if (time.IsDaylightSavingTime())
time = time.AddHours(1);
return time;
}
else
{
return null;
}
}
示例3: ToShortDateTime
public static string ToShortDateTime(DateTime date, bool twoLines)
{
var sb = new StringBuilder();
sb.Append(date.ToShortDateString());
sb.Append(twoLines ? "<br />" : " ");
sb.Append(date.ToShortTimeString());
sb.Append(date.IsDaylightSavingTime() ? " (pdt)" : " (pst)");
return sb.ToString();
}
示例4: UtcToUserTimeZoneShouldWork
public void UtcToUserTimeZoneShouldWork()
{
var utcDateTime = new DateTime(2014, 6, 1, 12, 0, 0, DateTimeKind.Utc);
Assert.IsFalse(utcDateTime.IsDaylightSavingTime());
var dateTime = Utils.UtcToUserTimeZone(utcDateTime, "GMT Standard Time");
Assert.IsTrue(Utils.IsGmtDaylightSavingTime(dateTime, "GMT Standard Time"));
}
示例5: DateFunctionality
public DateFunctionality()
{
DateTime dt = new DateTime(2004, 10, 17);
Console.WriteLine("The day of {0} is {1}", dt.Date, dt.DayOfWeek);
dt = dt.AddMonths(2);
Console.WriteLine("Daylight savings: {0}", dt.IsDaylightSavingTime());
TimeSpan timeSpan = new TimeSpan(4, 30, 0);
Console.WriteLine(timeSpan);
Console.WriteLine(timeSpan.Subtract(new TimeSpan(0,15,0)));
}
示例6: AlignWithTimezone
/// <summary>
/// Aligns a date/time with the User's preferences (if any).
/// </summary>
/// <param name="dateTime">The date/time to align.</param>
/// <returns>The aligned date/time.</returns>
public static DateTime AlignWithTimezone(DateTime dateTime)
{
// First, look for hard-stored user's preferences
// If they are not available, look at the cookie
int? tempShift = LoadTimezoneFromUserData();
if(!tempShift.HasValue) tempShift = LoadTimezoneFromCookie();
int shift = tempShift.HasValue ? tempShift.Value : Settings.DefaultTimezone;
return dateTime.ToUniversalTime().AddMinutes(shift + (dateTime.IsDaylightSavingTime() ? 60 : 0));
}
示例7: Print
public void Print()
{
System.Int32 i = new System.Int32();
i = 23;
Console.WriteLine(i.GetHashCode());
Console.WriteLine(i.GetType());
Console.WriteLine(i.GetTypeCode());
Console.WriteLine(i.ToString());
if (i.CompareTo(20) < 0)
Console.WriteLine("{0} < 20", i);
else if (i.CompareTo(20) == 0)
Console.WriteLine("i equals 20");
else
Console.WriteLine("i > 20");
Console.WriteLine(System.Int32.MinValue);
Console.WriteLine(System.Int32.MaxValue);
Console.WriteLine(System.Double.Epsilon);
Console.WriteLine(System.Double.PositiveInfinity);
Console.WriteLine(System.Double.NegativeInfinity);
Console.WriteLine(System.Boolean.FalseString);
Console.WriteLine(System.Boolean.TrueString);
Console.WriteLine(System.Char.IsDigit('1'));
Console.WriteLine(System.Char.IsLetter('9'));
Console.WriteLine(System.Char.IsWhiteSpace("naynish chaughule", 7));
Console.WriteLine(System.Char.IsPunctuation('?'));
//parsing
double d = System.Double.Parse("90.35");
Console.WriteLine(d);
System.Int64 longVar = Convert.ToInt64("43654703826562");
Console.WriteLine(longVar);
Console.WriteLine(System.Guid.NewGuid());
System.DateTime dt = new DateTime(2012, 6, 04);
Console.WriteLine(dt.ToLongDateString());
Console.WriteLine(DateTime.Now.ToLongTimeString());
Console.WriteLine(dt.DayOfWeek);
Console.WriteLine(dt.AddMonths(5).ToLongDateString());
Console.WriteLine("{0} {1} {2}", dt.Date, dt.DayOfYear, dt.IsDaylightSavingTime());
TimeSpan ts = new TimeSpan(24, 30, 30);
Console.WriteLine(dt.Add(ts).ToLongDateString());
Console.WriteLine(ts.Subtract(new TimeSpan(2,30, 45)));
NumericsDemo();
WorkingWithStrings();
}
示例8: DateTime_type
public DateTime_type ()
{
// This constructor takes (year, month, day).
DateTime dt = new DateTime( 2015, 10, 17);
// What day of the month is this?
Console.WriteLine(" The day of {0} is {1}", dt.Date, dt.DayOfWeek);
// Month is now December.
dt = dt.AddMonths( 2); Console.WriteLine(" Daylight savings: {0}", dt.IsDaylightSavingTime());
// This constructor takes (hours, minutes, seconds).
TimeSpan ts = new TimeSpan( 4, 30, 0);
Console.WriteLine( ts);
// Subtract 15 minutes from the current TimeSpan and
Console.WriteLine( ts.Subtract( new TimeSpan( 0, 15, 0)));
}
示例9: GetXsdtDateRepresentationForTest
public void GetXsdtDateRepresentationForTest()
{
XsdtTypeConverter target = new XsdtTypeConverter();
DateTime d = new DateTime(2007, 10, 17, 19, 42, 01); // TODO: Initialize to an appropriate value
XsdtPrimitiveDataType dt = XsdtPrimitiveDataType.XsdtDateTime; // TODO: Initialize to an appropriate value
XsdtAttribute attr = new XsdtAttribute(true, "dateTime"); // TODO: Initialize to an appropriate value
string expected = "2007-10-17T19:42:01+" + ((d.IsDaylightSavingTime())?"11:00":"10:00");
string actual;
XsdtTypeConverter tc = new XsdtTypeConverter();
actual = tc.GetXsdtDateRepresentationFor(d, dt, attr);
Assert.AreEqual(expected, actual,
"LinqToRdf.XsdtTypeConverter.GetXsdtDateRepresentationFor did not return the expec" +
"ted value.");
}
示例10: GetBuildRevisionAsDateTime
/// <summary>
/// Returns the versions build and revision components as a
/// <see cref="DateTime"/>.
/// </summary>
/// <remarks>
/// Note that this will only work correctly if the version was built
/// with the automatic version number feature turned on (eg Maj.Min.*).
/// </remarks>
/// <param name="version">Version to get the DateTime for.</param>
/// <returns>DateTime object for the build/revision.</returns>
public static DateTime? GetBuildRevisionAsDateTime(Version version) {
if (version == null) {
return null;
}
DateTime dt = new DateTime(2000, 1, 1, 0, 0, 0);
// If the start of the year is DLS but isn't now or vice versa then
// we need to either add or subtract an hour.
if (DateTime.Now.IsDaylightSavingTime() != dt.IsDaylightSavingTime()) {
if (DateTime.Now.IsDaylightSavingTime()) {
dt = dt.AddHours(1);
} else {
dt = dt.AddHours(-1);
}
}
dt = dt.AddDays(version.Build);
dt = dt.AddSeconds(version.Revision * 2);
return dt;
}
示例11: IeTime56
public IeTime56(long timestamp, TimeZone timeZone, bool invalid)
{
var datetime = new DateTime(timestamp);
var ms = datetime.Millisecond + 1000*datetime.Second;
value[0] = (byte) ms;
value[1] = (byte) (ms >> 8);
value[2] = (byte) datetime.Minute;
if (invalid)
{
value[2] |= 0x80;
}
value[3] = (byte) datetime.Hour;
if (datetime.IsDaylightSavingTime())
{
value[3] |= 0x80;
}
value[4] = (byte) (datetime.Day + ((((int) datetime.DayOfWeek + 5)%7 + 1) << 5));
value[5] = (byte) (datetime.Month + 1);
value[6] = (byte) (datetime.Year%100);
}
示例12: Main
static void Main(string[] args)
{
Console.WriteLine("=> Dates and Times");
// Этот конструктор принимает год, месяц и день
DateTime dt = new DateTime(2014, 10, 20);
// Какой это день месяца
Console.WriteLine("The day of {0} is {1}", dt.Date, dt.DayOfWeek);
// Сейчас месяц декабрь
dt = dt.AddMonths(1);
Console.WriteLine("Daylight savings: {0}", dt.IsDaylightSavingTime());
// Этот конструктор принимает часы, минуты и секунды
TimeSpan ts = new TimeSpan(8, 42, 30);
Console.WriteLine(ts);
// Вычесть 15 минут из текущего TimeSpan и вывести результат
Console.WriteLine(ts.Subtract(new TimeSpan(0, 15, 0)));
Console.ReadLine();
}
示例13: AlignWithServerTimezone
/// <summary>
/// Aligns a date/time with the default timezone.
/// </summary>
/// <param name="dateTime">The date/time to align.</param>
/// <returns>The aligned date/time.</returns>
public static DateTime AlignWithServerTimezone(DateTime dateTime)
{
return dateTime.ToUniversalTime().AddMinutes(Settings.DefaultTimezone + (dateTime.IsDaylightSavingTime() ? 60 : 0));
}
示例14: Today
public static void Today()
{
DateTime today = DateTime.Today;
DateTime now = DateTime.Now;
VerifyDateTime(today, now.Year, now.Month, now.Day, 0, 0, 0, 0, DateTimeKind.Local);
today = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, DateTimeKind.Utc);
Assert.Equal(DateTimeKind.Utc, today.Kind);
Assert.False(today.IsDaylightSavingTime());
}
示例15: AdjustTime_Win32ToDotNet
private DateTime AdjustTime_Win32ToDotNet(DateTime time)
{
// If I read a time from a file with GetLastWriteTime() (etc), I need
// to adjust it for display in the .NET environment.
if (time.Kind == DateTimeKind.Utc) return time;
DateTime adjusted = time;
if (DateTime.Now.IsDaylightSavingTime() && !time.IsDaylightSavingTime())
adjusted = time + new System.TimeSpan(1, 0, 0);
else if (!DateTime.Now.IsDaylightSavingTime() && time.IsDaylightSavingTime())
adjusted = time - new System.TimeSpan(1, 0, 0);
return adjusted;
}