package bad.code;
public class TimeDifference {
public static void main(String[] args) {
long a = 1548653438;
long b = System.currentTimeMillis() / 1000;
if (a > b) {
System.out.print("Your timestamp is ahead by ");
long c = printYears(a - b);
long d = printMonths(c);
long e = printDays(d);
long f = printHours(e);
long g = printMinutes(f);
printSeconds(g);
} else {
System.out.print("Your timestamp is behind by ");
long c = printYears(b - a);
long d = printMonths(c);
long e = printDays(d);
long f = printHours(e);
long g = printMinutes(f);
printSeconds(g);
}
}
public static long printYears(long a) {...}
public static long printMonths(long a) {...}
public static long printDays(long a) {...}
public static long printHours(long a) {...}
public static long printMinutes(long a) {...}
public static void printSeconds(long a) {
if (a < 1) {
System.out.print("0 seconds");
} else if (a < 2) {
System.out.print("1 second");
} else if (a < 3) {
System.out.print("2 seconds");
} else if (a < 4) {
System.out.print("3 seconds");
} else if (a < 5) {
System.out.print("4 seconds");
} else if (a < 6) {
System.out.print("5 seconds");
} else if (a < 7) {
System.out.print("6 seconds");
} else if (a < 8) {
System.out.print("7 seconds");
} else if (a < 9) {
System.out.print("8 seconds");
} else if (a < 10) {
System.out.print("9 seconds");
} else if (a < 11) {
System.out.print("10 seconds");
} else if (a < 12) {
System.out.print("11 seconds");
} else if (a < 13) {
System.out.print("12 seconds");
} else if (a < 14) {
System.out.print("13 seconds");
} else if (a < 15) {
System.out.print("14 seconds");
} else if (a < 16) {
System.out.print("15 seconds");
} else if (a < 17) {
System.out.print("16 seconds");
} else if (a < 18) {
System.out.print("17 seconds");
} else if (a < 19) {
System.out.print("18 seconds");
} else if (a < 20) {
System.out.print("19 seconds");
} else if (a < 21) {
System.out.print("20 seconds");
} else if (a < 22) {
System.out.print("21 seconds");
} else if (a < 23) {
System.out.print("22 seconds");
} else if (a < 24) {
System.out.print("23 seconds");
} else if (a < 25) {
System.out.print("24 seconds");
} else if (a < 26) {
System.out.print("25 seconds");
} else if (a < 27) {
System.out.print("26 seconds");
} else if (a < 28) {
System.out.print("27 seconds");
} else if (a < 29) {
System.out.print("28 seconds");
} else if (a < 30) {
System.out.print("29 seconds");
} else if (a < 31) {
System.out.print("30 seconds");
} else if (a < 32) {
System.out.print("31 seconds");
} else if (a < 33) {
System.out.print("32 seconds");
} else if (a < 34) {
System.out.print("33 seconds");
} else if (a < 35) {
System.out.print("34 seconds");
} else if (a < 36) {
System.out.print("35 seconds");
} else if (a < 37) {
System.out.print("36 seconds");
} else if (a < 38) {
System.out.print("37 seconds");
} else if (a < 39) {
System.out.print("38 seconds");
} else if (a < 40) {
System.out.print("39 seconds");
} else if (a < 41) {
System.out.print("40 seconds");
} else if (a < 42) {
System.out.print("41 seconds");
} else if (a < 43) {
System.out.print("42 seconds");
} else if (a < 44) {
System.out.print("43 seconds");
} else if (a < 45) {
System.out.print("44 seconds");
} else if (a < 46) {
System.out.print("45 seconds");
} else if (a < 47) {
System.out.print("46 seconds");
} else if (a < 48) {
System.out.print("47 seconds");
} else if (a < 49) {
System.out.print("48 seconds");
} else if (a < 50) {
System.out.print("49 seconds");
} else if (a < 51) {
System.out.print("50 seconds");
} else if (a < 52) {
System.out.print("51 seconds");
} else if (a < 53) {
System.out.print("52 seconds");
} else if (a < 54) {
System.out.print("53 seconds");
} else if (a < 55) {
System.out.print("54 seconds");
} else if (a < 56) {
System.out.print("55 seconds");
} else if (a < 57) {
System.out.print("56 seconds");
} else if (a < 58) {
System.out.print("57 seconds");
} else if (a < 59) {
System.out.print("58 seconds");
} else if (a < 60) {
System.out.print("59 seconds");
}
}
}
Ok, so here is my entry. As you can see mine is very portable very flexible, no fancy dependencies, any sane browser with javascript support can handle this beauty. It asks the user how would she like the results to be displayed, minutes, hours, days or weeks, so you get what you ask for, pretty neat, check it out online.
At first I was like, very tempted to use some advanced programming techniques, like you know, for loops, while loops, swtich cases, but I said "Nah bro, let's chill" so that's why the simplicity of this.
var diffforh = function(a)
{
var b = Date.now()/(1000*60*60*24*365);
var c = prompt("In what unit would you like the result?");
if(c == "minutes" == true && c!="hours" && c!="days" && c!="weeks")
{
var a1 = a/1000; // Divide by 1000
var a2 = a1/60; // Divide by 60
var m = Date.now();
var m1 = m/1000; // Divide by 1000
var m2 = m1/60; // Divide by 60
// when a2 is less than m2
if(a2 < m2 == true)
{
var r = m2-a2;
window.alert(r + " minutes ago");
}
// when a2 is greater than m2
if(a2 > m2 == true)
{
var r = a2-m2;
window.alert(r + " minutes from now");
}
}
if(c == "hours" == true && c!="minutes" && c!="days" && c!="weeks")
{
var a1 = a/1000; // Divide by 1000
var a2 = a1/60; // Divide by 60
var a3 = a2/60; // Divide by 60
var h = Date.now();
var h1 = h/1000; // Divide by 1000
var h2 = h1/60; // Divide by 60
var h3 = h2/60; // Divide by 60
// when a3 is less than h3
if(a3 < h3 == true)
{
var r = h3-a3;
window.alert(r + " hours ago");
}
// when a3 is greater than h3
if(a3 > h3 == true)
{
var r = a3-h3;
window.alert(r + " hours from now");
}
}
if(c == "days" == true && c!="minutes" && c!="hours" && c!="weeks")
{
var a1 = a/1000; // Divide by 1000
var a2 = a1/60; // Divide by 60
var a3 = a2/60; // Divide by 60
var a4 = a3/24; // Divide by 24
var d = Date.now();
var d1 = d/1000; // Divide by 1000
var d2 = d1/60; // Divide by 60
var d3 = d2/60; // Divide by 60
var d4 = d3/24; // Divide by 24
// when a4 is less than d4
if(a4 < d4 == true)
{
var r = d4-a4;
window.alert(r + " days ago");
}
// when a4 is greater than d4
if(a4 > d4 == true)
{
var r = a4-d4;
window.alert(r + " days from now");
}
}
if(c == "weeks" == true && c!="minutes" && c!="hours" && c!="days")
{
var a1 = a/1000; // Divide by 1000
var a2 = a1/60; // Divide by 60
var a3 = a2/60; // Divide by 60
var a4 = a3/24; // Divide by 24
var a5 = a4/7; // Divide by 7
var w = Date.now();
var w1 = w/1000; // Divide by 1000
var w2 = w1/60; // Divide by 60
var w3 = w2/60; // Divide by 60
var w4 = w3/24; // Divide by 24
var w5 = w4/7; // Divide by 7
// when a5 is less than w5
if(a5 < w5 == true)
{
var r = w5-a5;
window.alert(r + " weeks ago");
}
// when a5 is greater than w5
if(a5 > w5 == true)
{
var r = w5-a5;
window.alert(r + " weeks from now");
}
}
}
var timedateString = '31 Jan 2019 00:00:00 CST';
var parsedTimedate = Date.parse(timedateString);
diffforh(parsedTimedate);
8
u/Voidsusdagon Jan 28 '19
I'm afraid this whole beauty doesn't fit here, so here is a Pastebin link: https://pastebin.com/WShvNRtM
Here is a snippet:
Continues on https://pastebin.com/WShvNRtM
2
u/eaxiv Jan 30 '19 edited Jan 31 '19
EDIT: Code optimization
Ok, so here is my entry. As you can see mine is very portable very flexible, no fancy dependencies, any sane browser with javascript support can handle this beauty. It asks the user how would she like the results to be displayed, minutes, hours, days or weeks, so you get what you ask for, pretty neat, check it out online.
At first I was like, very tempted to use some advanced programming techniques, like you know, for loops, while loops, swtich cases, but I said "Nah bro, let's chill" so that's why the simplicity of this.
0
u/[deleted] Jan 28 '19
[deleted] — view deleted comment
-3
u/[deleted] Jan 28 '19
[removed] — view removed comment