Azure Data Factory:如何将UTC datetime转换为Unix Timestamp?
Got it, let's break down how to turn a UTC datetime string like 2021-11-08T07:25:00Z into a Unix Timestamp (like your example 1636385119) in Azure Data Factory. There are two common scenarios you'll run into—using ADF's expression language (for pipelines, datasets, etc.) and working within Data Flows.
1. Using ADF Expression Language (Pipeline/Dataset Scenarios)
ADF has built-in functions that make this straightforward. You'll need two main functions:
toDateTime(): Converts your UTC string into a proper datetime type (theZsuffix tells ADF this is UTC time, so no extra timezone conversion is needed here)unixTimeSeconds(): Calculates the number of seconds since the Unix epoch (1970-01-01T00:00:00Z) from a datetime value
Example Expression
If you're working with a hardcoded string (like your example):
unixTimeSeconds(toDateTime('2021-11-08T07:25:00Z'))
If you're pulling the UTC datetime from a column or parameter, replace the hardcoded string with your reference:
unixTimeSeconds(toDateTime(pipeline().parameters.UTC_Datetime))
Note: If your input datetime isn't already in UTC, you'll need to adjust it using convertTimeZone() first before passing it to unixTimeSeconds().
2. Using Data Flows
If you're transforming data in a Data Flow, use a Derived Column transformation to apply the same logic:
- Add a Derived Column to your Data Flow.
- In the expression builder, use this formula (replace
your_utc_datetime_columnwith your actual column name):
The format string ensures ADF correctly parses the UTC string with theunixTimeSeconds(toDateTime(your_utc_datetime_column, 'yyyy-MM-dd''T''HH:mm:ss''Z'''))Zsuffix.
Quick Note on Milliseconds
If you need a Unix Timestamp in milliseconds instead of seconds, just swap unixTimeSeconds() with unixTimeMilliseconds().
内容的提问来源于stack exchange,提问作者Akhilesh Jaiswal

