0

Axiom Script for Converting Epoch Microsecond Values to an Actual DateTime

This script uses the OnBeginValueChange function on a ValueBox to transform the value of tag which is recording the date/time in epoch microseconds to an actual date/time.

  • Ex:  1649721600000000 = 11 - Apr - 2022
public void ValueBox_OnBeginValueChange(object sender, TagSubscriptionArgs subscription, TVQ tvq)
        {
            // NOTE: Event is triggered BEFORE control property has been changed.
            // Any modifications to the `tvq` argument will be applied to the control.
            long unixMicroseconds;
            if(long.TryParse(tvq?.Value?.ToString() ?? "", out unixMicroseconds)) {
                DateTime dateTime = DateTimeOffset
                    .FromUnixTimeMilliseconds(unixMicroseconds/1000)
                    .ToLocalTime()
                    .DateTime;
                tvq.Value = dateTime.ToString("dd-MMM-yyyy");
            }
        }

 

 

Reply

null