Generate files with same milisecond in file name [ currentTimeMillis(); ]

Seven Stars

Generate files with same milisecond in file name [ currentTimeMillis(); ]

Hello all,

 

I have generated 3 csv files and the issue is that these files should have the same timestamp (currentTimeMillis) attached to them.

I have build 3 job for each of these files.

 

Example of file name should be : 

 

Customers_EN_1512484811837.csv

Adresses_EN_1512484811837.csv

Dependants_EN_1512484811837.csv

 

Is there a way to save the timestamp and use them when defining the filename?

Also what is the syntax to get to timestamp millisecond?

 

Thank you for your help.

 

Best regards,

asadasing


Accepted Solutions
Sixteen Stars

Re: Generate files with same milisecond in file name [ currentTimeMillis(); ]

At the beginning of your job place a tJava component. In that component, put the following code.....

 

String timeInMillis = routines.TalendDate.getCurrentDate().getTime()+"";
globalMap.put("timeInMillis", timeInMillis);

Then, when you want to name your files, use the following code....

"Filename_"+((String)globalMap.get("timeInMillis"))+".txt"

Obviously change the hardcoded parts to match your requirement.

 

EDIT: Just noticed this is essentially what @TRF said. We seem to keep replying at the same time. Sorry, didn't see you had commented.


All Replies
Forteen Stars TRF
Forteen Stars

Re: Generate files with same milisecond in file name [ currentTimeMillis(); ]

Use a tSetGlobalVar component when the job starts to get the value then reuse the variable where you want.

TRF
Sixteen Stars

Re: Generate files with same milisecond in file name [ currentTimeMillis(); ]

At the beginning of your job place a tJava component. In that component, put the following code.....

 

String timeInMillis = routines.TalendDate.getCurrentDate().getTime()+"";
globalMap.put("timeInMillis", timeInMillis);

Then, when you want to name your files, use the following code....

"Filename_"+((String)globalMap.get("timeInMillis"))+".txt"

Obviously change the hardcoded parts to match your requirement.

 

EDIT: Just noticed this is essentially what @TRF said. We seem to keep replying at the same time. Sorry, didn't see you had commented.

Seven Stars

Re: Generate files with same milisecond in file name [ currentTimeMillis(); ]

Thank you for the quick reply.

Can you provide me the syntax for milisecond to insert inthe value field?

 

Capture.PNG

 

Regards,

asadasing

Forteen Stars TRF
Forteen Stars

Re: Generate files with same milisecond in file name [ currentTimeMillis(); ]

Try something like this:
TalendDate.getDate("CCYYMMDDhhmmssSSS")
or play with the format

TRF
Sixteen Stars

Re: Generate files with same milisecond in file name [ currentTimeMillis(); ]

There is a subtle difference between what I showed and what @TRF is suggesting. The code I gave will return milliseconds after 1 Jan 1970, 00:00:00. The code @TRF has given will return a number representing years, months, days, hours, minutes, seconds, and milliseconds. Both are equally unique, but not the same.