Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
rp2018
Creator
Creator

How to add additional milliseconds to TalendDate.getCurrentDate()?

I'm using tJava component to set a context variable to add additional 10 seconds to the current date and have the context variable to be date format.  

 

This is what I got so far:

context.CurrentDate = TalendDate.getDate("yyyy-MM-dd HH:mm:ss.SSS");  
System.out.println("Current Date Is: "+context.CurrentDate);

 

NOTE: context.CurrentDate  is string type, but would like the results in datetype.

 

 

Labels (2)
1 Solution

Accepted Solutions
Aravind_Ravi
Contributor III
Contributor III

You Should Have to change the format of the date to see whether the 10ms is added are not.
Use the below code to test.

#code

String Date1 = TalendDate.getDate("yyyy-MM-hh mm:ss0683p000009M9p6.pngSS").toString();
System.out.println(TalendDate.getDate("yyyy-MM-hh mm:ss0683p000009M9p6.pngSS"));
System.out.println(TalendDate.addDate(Date1,"yyyy-MM-hh mm:ss0683p000009M9p6.pngSS", 10, "SSS"))

 

emoji value (Semicolon and S)

;

 

0683p000009M8Ua.png


If this is what you are looking for then, Press the "Accept as Solution " Button and Give A Kudos

Thanks,
AR

View solution in original post

3 Replies
cterenzi
Specialist
Specialist

TalendDate.addDate(TalendDate.getCurrentDate(),10,"ss") 

The code above will add 10 secs to the current date.  I confirmed this by defining a global variable with that formula.  

addDate() returns a Date object.  If you want to retain that, be sure to store the value in a Date variable.  Global variables don't have an explicit type, so if you store the value to a global var, make sure you cast it to a (Date) when you retrieve the value.

rp2018
Creator
Creator
Author

Sorry, I meant to add 10 milliseconds to it.

 

Used your code from seconds conversion to milliseconds and I'm not getting milliseconds.

I need the context.CurrentDate and context.CurrentDatePlus1ms to be date, but have

it in this format:  2019-11-16 10:06:19.642

 

context.CurrentDate = TalendDate.getCurrentDate();
System.out.println("Current Date: "+context.CurrentDate);


context.CurrentDatePlus1ms = TalendDate.addDate(context.CurrentDate,1,"SSS");
System.out.println("Current Date With 1ms Is: "+context.CurrentDatePlus1ms);

 

Output from the code:

Current Date: Wed Nov 06 15:34:32 CST 2019
Current Date With 1ms Is: Wed Nov 06 15:34:32 CST 2019

 

 

Aravind_Ravi
Contributor III
Contributor III

You Should Have to change the format of the date to see whether the 10ms is added are not.
Use the below code to test.

#code

String Date1 = TalendDate.getDate("yyyy-MM-hh mm:ss0683p000009M9p6.pngSS").toString();
System.out.println(TalendDate.getDate("yyyy-MM-hh mm:ss0683p000009M9p6.pngSS"));
System.out.println(TalendDate.addDate(Date1,"yyyy-MM-hh mm:ss0683p000009M9p6.pngSS", 10, "SSS"))

 

emoji value (Semicolon and S)

;

 

0683p000009M8Ua.png


If this is what you are looking for then, Press the "Accept as Solution " Button and Give A Kudos

Thanks,
AR