I am passing the current date and time “08-02-2021|11:45:30” and duration “3600”
and it’s returning “01-04-2021|12:45:30”
Here, the time is correct but it returning the wrong date why?
(Niotron Ide)
the code is
public String EndTime(String CrntTime, long durationInSec){
// Converting current date into milliseconds
SimpleDateFormat times = new SimpleDateFormat("MM-DD-YYYY|hh:mm:ss");
try{
Date date = times.parse(CrntTime);
long CurrentMillis = date.getTime();
//converting durationInSec to milliseconds
Date second = new Date(durationInSec*1000L);
long milliseconds = second.getTime();
//Adding in total
long totalmilli = CurrentMillis+milliseconds;
//converting milliseconds to datetime
SimpleDateFormat last = new SimpleDateFormat("MM-DD-YYYY|hh:mm:ss");
String java_date = last.format(totalmilli);
// returning the result
return java_date;
}catch(ParseException e){
return "CurrentTime must be in DD-MM-YYYY|hh:mm:ss format";
}
}
hope you guys help me. I am new extension developer
it takes the current time(in this format:
MM-DD-YYYY|hh:mm:ss
) and duration like 1 hour or more in second.
then adds two time in millisecond then again it returns the added millisecond in the format :
MM-DD-YYYY|hh:mm:ss
basically its job is to make a upcoming time acording to the given duration
String CrntTime = "08-03-2021 12:38:12";
long milliseconds = 3600; //For One hour
SimpleDateFormat times = new SimpleDateFormat("dd-MM-yyy HH:mm:ss");
Date date = null;
try{
date = times.parse(CrntTime);
}catch (ParseException e){
return "CurrentTime must be in dd-MM-yyy HH:mm:ss format";
}
/*Given time in milli*/
long CurrentMillis = date.getTime();
/*total milli*/
long totalmilli = CurrentMillis+ (milliseconds * 1000);
/*New time*/
String new_date = times.format(totalmilli);
return new_date;
here you write 3200
i) is this in second
if in second then we know I hour = 3600s
I am confused.If 3200 is correct then please explain me how did it happened
@tanishraj or @Faraz_Firoz can you guys help me.
I want to get the datetime from the response contants from http://worldtimeapi.org/api/ip
How to get the time.
moreover, is those library(Those libraries needed to get the time) is available natively or i have to import manually.
(Niotron IDE)