unix_to_tacc_time()

unix_to_tacc_time()#

unix_to_tacc_time(unix_time)

This function converts a Unix timestamp (the standard float or integer representing seconds since the Unix epoch 1970-01-01 00:00:00 UTC) into a TACC-style UTC timestamp string, matching the format typically returned by Tapis or TACC systems.

The output string looks like:

"2025-05-07T22:20:52.736325Z"

where:

  • The T separates date and time.

  • The fractional seconds provide precise timing.

  • The Z explicitly marks it as UTC (like ISO8601 with Z).

It preserves microseconds and explicitly marks the time as UTC with a Z suffix.

Use it alongside convert_tacc_time() to convert both ways.

Why it’s useful#

  • Logging events in a format consistent with Tapis or TACC jobs.

  • Generating timestamps for metadata that need to be uploaded to systems expecting this exact style.

  • Round-tripping from Unix time back to the original string format (for example after calculating durations).

  • Lets you format times for logs, reports, or re-upload to systems that expect this exact string format.

  • Keeps all your workflows consistent with how Tapis, TACC, and DesignSafe report timestamps.

Files#

You can find these files in Community Data.

unix_to_tacc_time.py
def unix_to_tacc_time(unix_time):
    """
    Convert a Unix timestamp back into a TACC-style UTC timestamp string.

    Produces strings like:
        "2025-05-07T22:20:52.736325Z"

    Parameters
    ----------
    unix_time : float or int
        The Unix timestamp (seconds since epoch).

    Returns
    -------
    str
        A UTC timestamp string with 'Z' suffix.

    Example
    -------
    ts_str = unix_to_tacc_time(1751884852.736325)
    print(ts_str)
    # → "2025-05-07T22:20:52.736325Z"

    Author
    ------
    Silvia Mazzoni, DesignSafe (silviamazzoni@yahoo.com)

    Date
    ----
    2025-08-14

    Version
    -------
    1.0
    """

    
    from datetime import datetime, timezone
    dt = datetime.fromtimestamp(unix_time, tz=timezone.utc)
    return dt.isoformat().replace('+00:00', 'Z')