1. Engineering
  2. Computer Science
  3. background a date object contains a number indicating a particular...

Question: background a date object contains a number indicating a particular...

Question details

Background:

A Date object contains a Number indicating a particular instant in time to within a millisecond. Such a Number is called a time value. A time value may also be NaN, indicating that the Date object does not represent a specific instant of time.

Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC. In time values leap seconds are ignored. It is assumed that there are exactly 86,400,000 milliseconds per day. ECMAScript Number values can represent all integers from -9,007,199,254,740,992 to 9,007,199,254,740,992; this range suffices to measure times to millisecond precision for any instant that is within approximately 285,616 years, either forward or backward, from 01 January, 1970 UTC.

The actual range of times supported by ECMAScript Date objects is slightly smaller: exactly -100,000,000 days to 100,000,000 days measured relative to midnight at the beginning of 01 January, 1970 UTC. This gives a range of 8,640,000,000,000,000 milliseconds to either side of 01 January, 1970 UTC.

The exact moment of midnight at the beginning of 01 January, 1970 UTC is represented by the value +0.

Assignment- Write the YearFromTime(t) function using if statements and while loops. The function requires entering a time (positive or negative in ms) and the output is the nearest year. It must take into account leap years. My program is not working and I'm not sure why. Can somebody tell me what I'm doing wrong? I have already written the following functions: TimeFromYear and DayFromYear.

YearFromTime(t) = the largest integer y (closest to positive infinity) such that TimeFromYear(y) ≤ t

(TimeFromYear(y) = msPerDay × DayFromYear(y)

DayFromYear(y)=365 × (y-1970) + floor((y-1969)/4) - floor((y-1901)/100) + floor((y-1601)/400))

int YearFromTime(long long int t) int yea r 1970; if(t >= 0) { while (TineFromYear(year) t) { <= yea r = (yea r + 1); else while { (TimeFromYear(year) year year 1; t) return year

mw111II /Description: DaysFromYear Computes the number of days since 1/1/1970 Input (type, name, description of variable): int year since 1/1/1970 //Output: int - number of days since 1/1/1970 int DayFromYear(int y) return (365 (y - 1970)+ floor((y - 1969)/ 4) - floor( (y - 1901)/ 100) +floor((y - 1601) / 400)) 1I //Description: TimeFromYear Computes the number of ms since 1/1/1978 Input (type, name, description of variable): int year since 1/1/1970 //Output: int number of ms since 1/1/1970 Long Long int TimeFromYear(int y) return (DayFromYear(y))(msPerDay);

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution