Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
AWS Degraded - You may experience Community slowness, timeouts, or trouble accessing: LATEST HERE
cancel
Showing results for 
Search instead for 
Did you mean: 
RA6
Creator
Creator

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

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable

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.

View solution in original post

5 Replies
TRF
Champion II
Champion II

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

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.

RA6
Creator
Creator
Author

Thank you for the quick reply.

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

 

0683p000009Lshs.png

 

Regards,

asadasing

TRF
Champion II
Champion II

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

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.