Converting epoch/UTC to the ITM Candletime date format

By Anthony Mico

Over the last few weeks I’ve written a number of custom ITM Agent Builder agents, several of which have included timestamp attributes.  Here is the Perl code I’ve used for converting a UTC/epoch time to the Candletime format used to populate an ITM Agent Builder Timestamp type attribute.

#!/usr/bin/perl

#

# Script to convert a utc/epoch time into Candletime

# CYYMMDDHHMMSSmmm (where C=1 for the 21st century)

#

# Call it without an argument to get the current time, or

# with an epoch to convert (noting that future/past DST changes

# etc are not supported).

#

# Millisecond value is always returned as 000.

#

# Ant Mico Orb Data Ltd.

use strict;

use warnings;

my $time = @ARGV ? shift : time;

my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($time))[0,1,2,3,4,5];

print map { sprintf("%02d", $_) } ($year, ++$mon, $mday, $hour, $min, $sec);

print "000";