Using Vincent Robert's answer, I want to rebuild it in Java.
I started off this way:
// This is a draft of the program.
import java.time.LocalDateTime;
import java.util.Scanner;
import java.lang.*;
public class Test
{
public String calcRelTime(int past_month, int past_day, int past_year)
{
// initialization of time values
int minute = 60;
int hour = 60 * minute;
int day = 24 * hour;
int week = 7 * day;
int month = (365.25 * day) / 12;
int year = 12 * month;
// main part of function
LocalDateTime present = LocalDateTime.now();
/*
Something similar to:
var ts = new TimeSpan(DateTime.UtcNow.Ticks - yourDate.Ticks);
double delta = Math.Abs(ts.TotalSeconds);
*/
// the if-condition statement similar to the answer, but I won't write it down here as it is too much code
}
public static void main(String[] args)
{
Scanner input;
int mon, day, year;
System.out.println("Enter date: ");
// the line where I take input of the date from the user
System.out.println("That was " + calcRelTime(mon, day, year) + ", fellow user.");
}
}
Now in the main()
function, I want to do something similar from C's scanf("%d/%d/%d", &mon, &day, &year);
. How can I implement something like that in Java using a single line?
I'm expecting this kind of input:
8/24/1995 12:30PM
%d/%d/%d %d/%d%cM