How to Convert time format in NiFi

Viewed 27

Team, I have a use case, i need to change the time format using jolt transformation and convert it to the specified format. Please suggest.

Input

{
  "operation": "default",
  "spec": {
    "createdon": "${now()}"
  }
}

output from this code, is like Fri Sep 23 13:14:17 IST 2022 but the

Desired Output

"2022-09-23T13:14:17.853Z"
1 Answers

You can start by formatting within the current default transformation spec, then add the letters within a modify spec such as

[
  {
    "operation": "default",
    "spec": {
        "createdon": "${now():format('yyyy-MM-ddHH:mm:ss.SSS')}"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "date": "=substring(@(1,createdon),0,10)",
      "time": "=substring(@(1,createdon),10,22)",
      "createdon":"=concat(@(1,date),'T',@(1,time),'Z')"     
    }
  },
  {
    "operation": "shift",
    "spec": {
        "cre*": "&"
    }
  }
]
Related