Porting a JavaScript function to Java












-5














I need to implement a JavaScript function in Java and use it in Android, but there is something wrong with my code:



function getwms(){
var a = Math.abs(Date.now() - Date.UTC(2E3));
return String.fromCharCode(97 + Math.floor(a/1E10%10)) + (a/1E7).toFixed(0)
}


That's how I tried:



private String getwms(){
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
int hrs = cal.get(Calendar.HOUR);
int min = cal.get(Calendar.MINUTE);
int sec = cal.get(Calendar.SECOND);

double abs = Math.abs(date.getTime() - Date.UTC(2000,month,day,hrs,min,sec));
return fromCharCode(97 + (int)Math.floor(abs/10000000000L*(10/100f))) + "" + (int)abs/10000000;

}

private static String fromCharCode(int... codePoints) {
return new String(codePoints, 0, codePoints.length);
}


Would anyone be able to help me?



This method (javascript) generates a key.
And it looks like this: 1542862172S183489e8a9c4f4958e5948e8739c8187S601h291h771h461










share|improve this question




















  • 4




    Would be helpful if you tell us what the method actually does.
    – SamzSakerz
    Nov 22 at 19:03






  • 1




    Date.UTC(2000,month,day,hrs,min,sec) is not the same as Date.UTC(2E3)
    – Andreas
    Nov 22 at 19:04










  • This method generates a key. And it looks like this: 1542862172S183489e8a9c4f4958e5948e8739c8187S601h291h771h461
    – Dima Chibuk
    Nov 22 at 21:36


















-5














I need to implement a JavaScript function in Java and use it in Android, but there is something wrong with my code:



function getwms(){
var a = Math.abs(Date.now() - Date.UTC(2E3));
return String.fromCharCode(97 + Math.floor(a/1E10%10)) + (a/1E7).toFixed(0)
}


That's how I tried:



private String getwms(){
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
int hrs = cal.get(Calendar.HOUR);
int min = cal.get(Calendar.MINUTE);
int sec = cal.get(Calendar.SECOND);

double abs = Math.abs(date.getTime() - Date.UTC(2000,month,day,hrs,min,sec));
return fromCharCode(97 + (int)Math.floor(abs/10000000000L*(10/100f))) + "" + (int)abs/10000000;

}

private static String fromCharCode(int... codePoints) {
return new String(codePoints, 0, codePoints.length);
}


Would anyone be able to help me?



This method (javascript) generates a key.
And it looks like this: 1542862172S183489e8a9c4f4958e5948e8739c8187S601h291h771h461










share|improve this question




















  • 4




    Would be helpful if you tell us what the method actually does.
    – SamzSakerz
    Nov 22 at 19:03






  • 1




    Date.UTC(2000,month,day,hrs,min,sec) is not the same as Date.UTC(2E3)
    – Andreas
    Nov 22 at 19:04










  • This method generates a key. And it looks like this: 1542862172S183489e8a9c4f4958e5948e8739c8187S601h291h771h461
    – Dima Chibuk
    Nov 22 at 21:36
















-5












-5








-5







I need to implement a JavaScript function in Java and use it in Android, but there is something wrong with my code:



function getwms(){
var a = Math.abs(Date.now() - Date.UTC(2E3));
return String.fromCharCode(97 + Math.floor(a/1E10%10)) + (a/1E7).toFixed(0)
}


That's how I tried:



private String getwms(){
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
int hrs = cal.get(Calendar.HOUR);
int min = cal.get(Calendar.MINUTE);
int sec = cal.get(Calendar.SECOND);

double abs = Math.abs(date.getTime() - Date.UTC(2000,month,day,hrs,min,sec));
return fromCharCode(97 + (int)Math.floor(abs/10000000000L*(10/100f))) + "" + (int)abs/10000000;

}

private static String fromCharCode(int... codePoints) {
return new String(codePoints, 0, codePoints.length);
}


Would anyone be able to help me?



This method (javascript) generates a key.
And it looks like this: 1542862172S183489e8a9c4f4958e5948e8739c8187S601h291h771h461










share|improve this question















I need to implement a JavaScript function in Java and use it in Android, but there is something wrong with my code:



function getwms(){
var a = Math.abs(Date.now() - Date.UTC(2E3));
return String.fromCharCode(97 + Math.floor(a/1E10%10)) + (a/1E7).toFixed(0)
}


That's how I tried:



private String getwms(){
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
int hrs = cal.get(Calendar.HOUR);
int min = cal.get(Calendar.MINUTE);
int sec = cal.get(Calendar.SECOND);

double abs = Math.abs(date.getTime() - Date.UTC(2000,month,day,hrs,min,sec));
return fromCharCode(97 + (int)Math.floor(abs/10000000000L*(10/100f))) + "" + (int)abs/10000000;

}

private static String fromCharCode(int... codePoints) {
return new String(codePoints, 0, codePoints.length);
}


Would anyone be able to help me?



This method (javascript) generates a key.
And it looks like this: 1542862172S183489e8a9c4f4958e5948e8739c8187S601h291h771h461







javascript java android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 21:39

























asked Nov 22 at 19:00









Dima Chibuk

32




32








  • 4




    Would be helpful if you tell us what the method actually does.
    – SamzSakerz
    Nov 22 at 19:03






  • 1




    Date.UTC(2000,month,day,hrs,min,sec) is not the same as Date.UTC(2E3)
    – Andreas
    Nov 22 at 19:04










  • This method generates a key. And it looks like this: 1542862172S183489e8a9c4f4958e5948e8739c8187S601h291h771h461
    – Dima Chibuk
    Nov 22 at 21:36
















  • 4




    Would be helpful if you tell us what the method actually does.
    – SamzSakerz
    Nov 22 at 19:03






  • 1




    Date.UTC(2000,month,day,hrs,min,sec) is not the same as Date.UTC(2E3)
    – Andreas
    Nov 22 at 19:04










  • This method generates a key. And it looks like this: 1542862172S183489e8a9c4f4958e5948e8739c8187S601h291h771h461
    – Dima Chibuk
    Nov 22 at 21:36










4




4




Would be helpful if you tell us what the method actually does.
– SamzSakerz
Nov 22 at 19:03




Would be helpful if you tell us what the method actually does.
– SamzSakerz
Nov 22 at 19:03




1




1




Date.UTC(2000,month,day,hrs,min,sec) is not the same as Date.UTC(2E3)
– Andreas
Nov 22 at 19:04




Date.UTC(2000,month,day,hrs,min,sec) is not the same as Date.UTC(2E3)
– Andreas
Nov 22 at 19:04












This method generates a key. And it looks like this: 1542862172S183489e8a9c4f4958e5948e8739c8187S601h291h771h461
– Dima Chibuk
Nov 22 at 21:36






This method generates a key. And it looks like this: 1542862172S183489e8a9c4f4958e5948e8739c8187S601h291h771h461
– Dima Chibuk
Nov 22 at 21:36



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436806%2fporting-a-javascript-function-to-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436806%2fporting-a-javascript-function-to-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Futebolista

Lallio

Jornalista