Announcement

Collapse
No announcement yet.

Get current date & time in ISO format

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Get current date & time in ISO format

    Hi,

    I need to grab the current time and date, format it to ISO and add 20 minutes.
    I use it for boosting my thermostat which only accepts a temporary setpoint change if the request is combined with a future date.
    I don't want to use it with a distant future date like 2080 as I want it to automatically shut off after 20 minutes.

    I currently use a script in LUA which works fine but have no clue in vb.net, it could be in vb script but it must be easier in .net
    The output needs to be:

    Code:
    2017-06-26T00:00:00.00Z
    Thanks

    #2
    Code:
    Sub Main(ByVal Parms As String)
    
        Dim tm As DateTime = DateTime.Now.AddMinutes(20)
        'Dim tmiso As String = tm.ToString("o")
        Dim tmiso As String = tm.ToString("yyyy-MM-ddTHH:mm:ssZ")
        hs.writelog("Time ISO",tmiso)
    
    End Sub
    The first one which is remarked out would provide the output with milliseconds.

    If you want the time in UTC change the first line to:

    Code:
    Dim tm As DateTime = DateTime.UtcNow.AddMinutes(20)
    Jon

    Comment


      #3
      Originally posted by jon00 View Post
      Code:
      Sub Main(ByVal Parms As String)
      
      Dim tm As DateTime = DateTime.Now.AddMinutes(20)
      'Dim tmiso As String = tm.ToString("o")
      Dim tmiso As String = tm.ToString("yyyy-MM-ddTHH:mm:ssZ")
      hs.writelog("Time ISO",tmiso)
      
      End Sub
      The first one which is remarked out would provide the output with milliseconds.

      If you want the time in UTC change the first line to:

      Code:
      Dim tm As DateTime = DateTime.UtcNow.AddMinutes(20)
      I sometimes think you're the only one on these forums Jon.
      I'm also beginning to think you work for HST as you spend so much time here

      Thanks for this. I actually got the time part sorted last night and came up with almost the same.
      But I was trying to use TimeSpan to add minutes which get causing errors the way i tried it.

      Anyway thanks.

      Comment

      Working...
      X