mc-Things

mc-Products => mc-Studio => Topic started by: GarnetT on May 15, 2017, 08:44:01 pm

Title: Timestamps
Post by: GarnetT on May 15, 2017, 08:44:01 pm
Is anyone having much luck with the time functions? Specifically I want to return the current hour from modul . Secondly, when I read this value, the format (converted to string) appears as such:
2017-05-16T00:59:59+00:00

My PC clock is reading that same date, but the time is 7:42 pm. Hours, minutes, and seconds seem to be a bit off.
None the less, I still want to fetch the hours integer value.

Garnet
Title: Re: Timestamps
Post by: Nick_W on May 20, 2017, 01:36:32 pm
Checkout my Time library, everything i know about timestamps is in it.

BTW the module time is really the gateway time (obtained from NTP server), and sent to the module when it connects. Timezone doesn't really seem to work though...
Title: Re: Timestamps
Post by: GarnetT on May 21, 2017, 09:34:14 am
Thanks Nick,
I've just google'd you and am checking it out now.
Garnet
Title: Re: Timestamps
Post by: bdevlin on July 09, 2017, 01:08:19 pm
I can't seem to get datetime.now() until the second request from a module. It kinda makes sense I guess, but that means the modules first response is bad data.
Title: Re: Timestamps
Post by: mc-John on July 10, 2017, 11:17:11 am
The code to get date/time info looks like this:

Code: [Select]
        Dim dat As DateTime = DateTime.Now
        Dim hr As Integer = dat.Hour
        Dim sec As Integer = dat.Second
        Dim month As Integer = dat.Month
Title: Re: Timestamps
Post by: bdevlin on July 12, 2017, 02:53:17 pm
I can get data from DateTime.Now() but The data transmitted via publish in the first module boot is "2000-01-01T00:00:00+00:00", then the second and subsequent publish the time nearly correctly, however it's off by an hour (-8:00N is my time zone). I can't figure out how to force the module to fetch the time fist in the boot() event successfully first.

This seems to work ok, any problems with this method?

    Shared Event Boot()
        While DateTime.Now().Year= 2000
        End While
    End Event
Title: Re: Timestamps
Post by: mc-John on July 17, 2017, 09:21:06 am
That will work. To limit power consumption you could sleep for 100mSec in the while loop.
Title: Re: Timestamps
Post by: bdevlin on July 17, 2017, 01:35:04 pm
So that would be this in uSeconds?

        While DateTime.Now().Year= 2000
            Thread.Sleep(100000)   
        End While
Title: Re: Timestamps
Post by: mc-John on July 18, 2017, 09:56:46 am
That's correct