Friday, May 1, 2009

Methods used in Now function...

Our blog task this week is to list the methods that can be used in the Now function. Our assessment involved using the Now function, but we used it in a very simple way. So Rachael has given us this task to show what other methods can be used.

If you want to display the time in a label for example, you might use something like this:
lblCurrentTime.Text = Now
This will retrieve the current time and date from the computer and display it in the label lblCurrentTime. If you only want to display the time though, you would need to do it like this:
lblCurrentTime.Text = Now.ToString("HH:mm:ss")
This will display the time in Hours, Minutes and Seconds. It will only show the time when the program starts though, it won't keep updating the time to keep it current. If you want it to act like a clock, you need to add a Timer function and put this code in to the function as well.






I have been posting a little bit on this function in recent times, relating to my sleep calculator. What I'm going to do is use this function to create a real, bonafide sleep calculator, but that will have to wait until the workload of assignments has thinned out a little bit.
Anyway, what other methods can be added to the Now function? So far ToString has been added. According to the list in Intellisense, the following can be added as methods to the Now function:
  • Add (AddDays, AddHours, AddMilliseconds, AddMinutes, AddMonths, AddSeconds, AddTicks, AddYears)
  • To (ToString, ToLongTimeString, ToOADate, ToShortDateString, ToShortTimeString, ToUniversalTime, ToBinary, ToFileTime, ToFileTimeUtc, ToLocalTime)
  • TryParse, TryParseExact
  • Compare, CompareTo
  • DaysInMonth
  • Equals
  • From (FromBinary, FromFileTime, FromFileTimeUtc, FromOADate)
  • Get (GetDateTimeFormat, GetHashCode, GetType, GetTypeCode)
  • IsDaylightSavingTime, IsLeapYear
  • Parse, ParseExact
  • ReferenceEquals
  • SpecifyKind
  • Subtract
I spent a couple of hours searching the internet looking for a list like this one. Once I finally used my brain however, I realised that I could find what I needed in Intellisense. I'm not too sure what it is that all of these methods do, but I'm sure we'll be finding out at least some of them in the coming months.

2 comments:

  1. Good old Intellisense! I guess I must have a modicum of Intellisense myself as I looked there first :o).

    ReplyDelete
  2. Well done Deb.

    Mind you, if there is a hard way to do something, I will find and use it. It's uncanny really. :-)

    ReplyDelete