Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to use modular programming to return: Date (day and month), Time (24hr fo

ID: 643931 • Letter: I

Question

I need to use modular programming to return: Date (day and month), Time (24hr format), and the day of the week from a user input value in seconds.

An example output would be 23:01:01 8 March 2015 Tuesday

The start date is 00:00:00 1 January 2015

The trick is I cannot use Matlab functions to accomplish this...

Here is what I have so far...

%TimeCalc

%User will enter a time in seconds and TimeCalc will output the
%Seconds in a day = 86400
%Seconds in a week = 604800
%Seconds in a year = 31536000
%Seconds in a leap year = 31622400

%Initialize
clc

yr=31536000;
d=86400;
wk=604800;
startyear = 2015;
startdate = 1/1;
starttime = 00:00:00;

%Get user input in seconds

secs = input('Enter elapsed time in seconds: ');

%Calculate year

year = floor((secs/yr))+startyear;

%Determine if leap year

function[status] = leapyear(year)
if mod(year,4) == 0
status=true;
if mod(year,100) == 0
status=false;
if mod(year,400)==0
status=true;
end
end
else
status=false;
end

%Calculate month

Explanation / Answer

## locale-specific version of date() format(Sys.time(), "%a %b %d %X %Y %Z") ## time to sub-second accuracy (if supported by the OS) format(Sys.time(), "%H:%M:%OS3") ## read in date info in format 'ddmmmyyyy' ## This will give NA(s) in some locales; setting the C locale ## as in the commented lines will overcome this on most systems. ## lct