How to split a time in hours, minutes and seconds

Just like we can split a date into the year, month and day part, we can do something similar for a time.  We can split the time into hours, minutes and seconds.  And the nice part: we can use the same tool for this as we use for splitting a date.  We can use the DateTimeUtil class.


Here's a short example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
static void GetMyTimeSplit(Args _args)
{  
    TransDateTime   myDateTime=DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(),Timezone::GMTPLUS0100BRUSSELS_COPENHAGEN_MADRID);
    int             hours;
    int             minutes;
    int             seconds;
    ;
    info(datetime2str(myDateTime));
     
    hours=DateTimeUtil::hour(myDateTime);
    minutes=DateTimeUtil::minute(myDateTime);
    seconds=DateTimeUtil::second(myDateTime);
    info(strfmt('Hours %1 - Minutes %2 - Seconds %3',int2str(hours),int2str(minutes),int2str(seconds)));
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.