Extension development help

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

your post has been deleted

Is you got any error in compiling extension

What was you really do with this extension

no, no compiling extension. I am getting the following error mentioned in the top

First of all tell me this

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

Set format in yyyy-mm-dd | hh:mm:ss

1 Like

It’s because in Java the milliseconds obtained are the milliseconds between the desired epoch and 1970-01-01 00:00:00.

Do this, long totalmilli = CurrentMillis+ (milliseconds * 1000 );


Imports

import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.ParseException;

Codes

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;

Note: Make a @SimpeFunction

Because, After August, 1 file type has been changed. now you have to compile your app in .abb format

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

Thank you for your help

:sweat_smile: Yeah that’s 3600s for 1hr

Updated that

1 Like

Close this topic he had got his solution

1 Like

In this I dont know why no solution button or no close topic option?

@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)

I can not understand what are you saying

I want to say that how do I get this( http://worldtimeapi.org/api/ip ) page’s source code

Use this repo to learn how to mae server calls, make HTTP get request to the given url… Parse response and return desired data


But what kind of problem is this?

Solution has been given thousands of time, please stop posting the same thing in every post