Java USES the Chinese way to display the time method
- 2020-04-01 04:01:08
- OfStack
This article illustrates a method of displaying time in Java in Chinese. Share with you for your reference. The details are as follows:
Where t is seconds, for example, it is sometimes necessary to calculate how long the two tasks are different, or when the task ends or how long a task is restarted, etc., which is applicable to this method. If it's microseconds, I'm going to divide by 1000
private static String chinese_period(int t){
int y, n, d, h, m, s;
String time;
if(t<=0) return " immediately ";
s = t % 60; t /= 60;
m = t % 60; t /= 60;
h = t % 24; t /= 24;
d = t % 30; t /= 30;
n = t % 12; t /= 12;
y = t;
time = "";
if(y>0) time = y + " Years and ";
if(n>0) time += n + " months ";
if(d>0) time += d + " day ";
if(h>0) time += h + " hours ";
if(m>0) time += m+ " points ";
if(s>0) time += s + " seconds ";
return time;
}
I hope this article has been helpful to your Java programming.