DateTime
SpecifyKind
DateTime dt = new DateTime(2017, 1, 1, 10, 0, 0); // dt = 01/01/2017 10:00:00 in unspecified time zone var dt2 = DateTime.SpecifyKind(dt, DateTimeKind.Utc); // dt2 = 01/01/2017 10:00:00 UTC
DateTime?
declare @PropertyName varchar(100) = 'LastEditedOn' ,@Nullable bit = 1 declare @PrivateVariable varchar(101) = '_' + lower(substring(@PropertyName, 1, 1)) + substring(@PropertyName, 2, 99) ,@DataType varchar(30) = 'DateTime' + case when @Nullable = 1 then '?' else '' end select Seq = 100 ,Code = 'private ' + @DataType + ' ' + @PrivateVariable + ';' union select 110, 'public ' + @DataType + ' ' + @PropertyName union select 120, '{' union select 130, ' get { return ' + @PrivateVariable + '; }' union select 140, ' set { ' + @PrivateVariable + ' = ' + case when @Nullable = 1 then 'value == null ? (DateTime?)null : ' + 'DateTime' + '.SpecifyKind(value.Value, DateTimeKind.Utc)' else 'DateTime.SpecifyKind(value, DateTimeKind.Utc)' end + '; }' union select 150, '}'
private DateTime? _lastEditedOn; public DateTime? LastEditedOn { get { return _lastEditedOn; } set { _lastEditedOn = value == null ? (DateTime?)null : DateTime.SpecifyKind(value.Value, DateTimeKind.Utc); } }
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.