|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DateTime structureHello
Is it possible to create a DateTime structure that does not include the date? I am only intrested in the time and day. for example 23:00 Mon. I would eventually like to add and subtract hours to based on a UTC calculation. any help is greatly appreciated. Arrrrgg!!! this is so frustrating.
I am trying the following Dim MyTime As System.DateTime MyTime = System.DateTime.Parse("8:00 mon") MyTime = MyTime.AddHours(-11) MyTime = MyTime.AddHours(-5) MsgBox(MyTime.ToString("HH:mm ddd")) but it only works on the day equivelant to today, in this case monday.. If I plug in 8:00 Tue through sun it errors. Is there any way to accomplish this? It seems to still be bound to a date. I am trying to convert a shift schedule from Sydney time, to Eastern. I do not care about the date, just the day ranges and hours. Is there any way to do this? I think that, for this exercise, because the date is irrelevant, you need to
create your own class that does some number crunching without using DateTime structures at all. Using the example you have given, it might be something like: Public Class MyScheduleItem Public Shared Function ConvertLocalToRemote(ByVal LocalTimeOfDay As Integer, ByVal LocalDayOfWeek As DayOfWeek, ByVal RemoteOffset As Integer) As String Dim _RemoteTimeOfDay As Integer = LocalTimeOfDay + RemoteOffset Dim _RemoteDayOfWeek As DayOfWeek = LocalDayOfWeek Select Case _RemoteTimeOfDay Case < 0 _RemoteDayOfWeek = CType(Convert.ToInt32(_RemoteDayOfWeek) - 1, DayOfWeek) _RemoteTimeOfDay = 1440 + _RemoteTimeOfDay Case >= 1440 _RemoteDayOfWeek = CType(Convert.ToInt32(_RemoteDayOfWeek) + 1, DayOfWeek) End Select Select case _RemoteDayOfWeek Case < DayOfWeek.Sunday _RemoteDayOfWeek = DayOfWeek.Saturday Case > DayOfWeek.Saturday _RemoteDayOfWeek = DayOfWeek.Sunday End Select Return String.Format("{0:#0}:{1:00} {2}", Fix(_RemoteTimeOfDay \ 60) , _RemoteTimeOfDay Mod 60, _RemoteDayOfWeek.ToString.SubString(0,3)) End Sub End Class Note that LocalTimeOfDay, _RemoteTimeOfDay and RemoteOffset are in units of minutes thus handling times of day and offsets that are not whole hours. Note also that the week is deemed to run from Sunday (0) to Saturday (6). Call it with: Console.WriteLine(MyScheduleItem.ConvertLocalToRemote(8 * 60, DayOfWeek.Monday, -(16 * 60))) Dissect it to your hearts content to see how it works and improve on it. Show quoteHide quote "Paulers" <SuperG***@gmail.com> wrote in message news:1139885729.828315.196990@g14g2000cwa.googlegroups.com... > Arrrrgg!!! this is so frustrating. > > I am trying the following > > Dim MyTime As System.DateTime > MyTime = System.DateTime.Parse("8:00 mon") > MyTime = MyTime.AddHours(-11) > MyTime = MyTime.AddHours(-5) > MsgBox(MyTime.ToString("HH:mm ddd")) > > but it only works on the day equivelant to today, in this case monday.. > If I plug in 8:00 Tue through sun it errors. Is there any way to > accomplish this? It seems to still be bound to a date. I am trying to > convert a shift schedule from Sydney time, to Eastern. I do not care > about the date, just the day ranges and hours. > > Is there any way to do this? > |
|||||||||||||||||||||||