Skip to Content
Technical Articles
Author's profile photo Nick Yang

Using local time zone for target file name in Cloud Platform Integration

* * * * Update Start * * * *

Thanks great tips from Emre Ozkan.

You can put timezone informatoin in the expression like below and then get local date and time without using script.


I tested the above expression in CPI (build number 6.14.13) and it works perfectly!

* * * * Update End * * * *

In this blog, I am going to share how I came across time zone when I tried to use local time zone to be the target file name on Cloud Platform Integration (CPI).


My requirement is that I want to create a file on receiver system and the name of this file is local time when file generated. Something like 20180228T2156.txt. So, I started exploring how CPI can help me to achieve this.

First I tried with following Camel’s Simple expression in the File Name field inside SFTP adapter:


date:<command>:<pattern> for date formatting using the SimpleDateFormat patterns. Supported commands are: now for current timestamp. If you are not familiar with Camel’s Simple expression language, please read through [1] and [2] in the references.

I thought this is the one to solve my problem, but after ran my integration flow. The generated file name is not what I expect. It is in UTC time but not local time. So, any other options in this expression I can set to have result in local time zone? I tried many different patterns in SimpleDateFormat, but still can’t find a way to get what I want.

My next trying is to use groovy script to generate the local date time string for the file name. Below small code snippet helps me to generate local date and time and it’s correct when time zone is in day light saving. I save the formatted string into message header for later used in SFTP channel configuration.

import java.util.HashMap;
import static java.util.Calendar.*;
def Message processData(Message message) {    
    def localTimeZone = TimeZone.getTimeZone('Australia/Melbourne');
    def cal = Calendar.instance;
    def date = cal.time;
    def dateFormat = 'ddMMyyyy\'T\'HHmm';
    message.setHeader("CamelFileName", date.format(dateFormat, localTimeZone) + '.csv');     
    return message;


In SFTP adapter Target tab, I enter ${header.CamelFileName} in File Name field to retrieve the value I save in the script. All in the end I get my desired result. Now, it’s much better than using UTC time.


[1] Get to know Camel’s Simple expression language in HCI by Morten Wittrock

[2] Apache Camel SimpleLanguage JavaAPI


Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Emre Ozkan
      Emre Ozkan

      You can also use this expression so you do not need the script


      Adjust the timezone and format as required.