format
Converts a Date to a String in the given format with an optional time zone. The function defaults to the system local time zone when the second argument is not provided.
The first argument to this function must be a Date or a Number, and the second argument must be a format String that follows the Java SimpleDateFormat, and the third argument, optional, must be a format String that either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "GMT-8:00"
For example, given a schema such as:
{
"type": "record",
"name": "events",
"fields": [
{ "name": "name", "type": "string" },
{ "name": "eventDate", "type" : { "type" : "long", "logicalType" : "timestamp-millis" } }
]
}
and a record such as:
{
"name" : "My Event",
"eventDate" : 1508457600000
}
The following record path expressions would format the date as a String:
RecordPath |
Return value |
|
2017-10-20T00:00:00Z |
|
2017-10-20 |
|
2017-10-20 08:00:00 +0800 |
|
2017-10-20 |
In the case where the field is declared as a String, the toDate function must be called before formatting.
For example, given a schema such as:
{
"type": "record",
"name": "events",
"fields": [
{ "name": "name", "type": "string" },
{ "name": "eventDate", "type" : "string"}
]
}
and a record such as:
{
"name" : "My Event",
"eventDate" : "2017-10-20T00:00:00Z"
}
The following record path expression would re-format the date String:
RecordPath |
Return value |
|
2017-10-20 |