Subtracting two dates with time in JSTL [duplicate] - java

This question already has answers here:
display Date diff in jsp
(3 answers)
Closed 8 years ago.
Let's say I have two variables called AdmittedDate and currentDate. They contain values like
"2014-10-13 14:47:44.0"
I want to cast them into dates and subtract them and show them in webpage. Can someone help?

JavaScript
var differenceInMin=(new Date(AdmittedDate ).getMilliseconds()-new Date(currentDate).getMilliseconds())/60000;
var diffInHrs=differenceInMin/60;
var diffInDays=parseInt(diffInHrs/24)+" "+parseInt(diffInHrs)+":"+((diffInHrs-parseInt(diffInHrs))*60);

Related

Kotlin : How to convert Array<List> to arrayof? [duplicate]

This question already has answers here:
Java ArrayList to Kotlin Array
(4 answers)
Closed 1 year ago.
So, I try to make a line chart using AAChartModel. I have ArrayList in my code. But in AAchartModel they used an arrayOf instead of ArrayList.
So My Question is, how do I convert from ArrayList to arrayOf ?
arrayOf() returns just an Array. So you can call arrayList.toTypedArray()

java-Not getting the result with decimal places [duplicate]

This question already has answers here:
Why does integer division code give the wrong answer? [duplicate]
(4 answers)
Closed 6 years ago.
I am doing simple calculation in java. Expected result is 51.3348 but what I am getting is 51.0, here is my calculation
float percent = (7819140000l-3805200000l)*100/7819140000l;
Is that problem with datatype? How can I resolve this to get value as 51.3348
Thanks in Advance
add an f to one of the values:
float percent = (7819140000l-3805200000l)*100f/7819140000l;
if yiu do not do it, Java will make a devision by long values

How to Make Java Recognize A Zero [duplicate]

This question already has answers here:
Best way to Format a Double value to 2 Decimal places [duplicate]
(2 answers)
Closed 7 years ago.
The title says it all. Right now if I input a number like 100.50, in my program it prints as 100.5. Is there an easy way to make the program recognize the zero?
You can do this trick.
String s = String.format("%.2f", 100.50);

simple time countdown string [duplicate]

This question already has answers here:
Countdowntimer in minutes and seconds
(4 answers)
Closed 8 years ago.
i am sorry for asking question that already answered in other post.
i already have tick method running each second, since i don't know about time format, i only display counter (int variable type) from 1800 (30 minutes) , subtract it one (sec) by each tick , until 0.
can you teach me how to make it to display 30:00, 29:59 .. instead of 1800,1799 until 00:00 ..?
if possible, i don't want to implement any other method to get it done. if you have any idea how to make this possible as simple as possible.. e.g by using time or date type
thank you.
You need to use the timedelta() method from the datetime module. You can use it as follows :
import datetime
your_nicely_formated_countdown_value = datetime.timedelta(seconds=your_current_tick_value))
For instance,
import datetime
print(str(datetime.timedelta(seconds=300)))
# => '0:05:00'

List from encoded string [duplicate]

This question already has answers here:
How can I check if a single character appears in a string?
(16 answers)
Closed 9 years ago.
I have a string like :
"\"[\"a\",\"b\", \"c\"]\""
How to convert this to a list of strings
Could you suggest me a nice way of doing it in Java?
str.contains("c") does this job. However did not you think to consult String class documentation first?
Use contains():
if (str.contains("\"c\""))

Categories

Resources