MATLAB QUESTION Computer users and applications need the time and date for vario
ID: 3758002 • Letter: M
Question
MATLAB QUESTION
Computer users and applications need the time and date for various reasons. This can be achieved by keeping track of the number of seconds that have elapsed since some reference date and time. The number of seconds elapsed can then be convened to determine the current date and time. (The built-in MATLAB functions that do something like this include date and clock.) For this assignment, your will write a program (consists of script and user-defined function files) to determine the time and date corresponding to an elapsed number of seconds since 00: 00: 00 on 1 January. 2015. Have the user input the value of elapsed seconds. The output (to the screen) should be the hour (in military time), minute, second, day of the month, month name, year, and day of the week name (Sunday - Saturday). Your output should look like the following: 23:59:32 2 January 2015 Monday Don't forget that a leap year has 366 days with 29 days in February. Leap years are years that are evenly divisible by 4, with the exception of those evenly divisible by 100 but not 400. Your program should be accomplished using the assignment operator (=), mathematical operators ( +, -, /, *, ^), logical operators ( &, |, ~), relational operators (==,Explanation / Answer
C# program that calculates elapsed time
using System;
class Program
{
static void Main()
{
// Initialize a date in the past.
// This is March 3, 2008.
string someDate = "03-03-2008";
// 1.
// Parse the date and put in DateTime object.
DateTime startDate = DateTime.Parse(someDate);
// 2.
// Get the current DateTime.
DateTime now = DateTime.Now;
// 3.
// Get the TimeSpan of the difference.
TimeSpan elapsed = now.Subtract(startDate);
// 4.
// Get number of days ago.
double daysAgo = elapsed.TotalDays;
Console.WriteLine("{0} was {1} days ago",
someDate,
daysAgo.ToString("0"));
}
}
Output
3-03-2008 was 247 days ago
MATLAB
%# your data
data = {
'START: 2013-05-04 23:13:06.188'
'ENDED: 2013-05-05 1:22:41.617'
};
%# extract date/time strings
s = regexprep(data, '^w+: ', '');
%# convert to serial date number (in units of days)
t1 = datenum(s{1}, 'yyyy-mm-dd HH:MM:SS.FFF');
t2 = datenum(s{2}, 'yyyy-mm-dd HH:MM:SS.FFF');
%# difference in seconds
diff_sec = (t2-t1) * 24 * 3600
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.