Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- convdate.c -
- Tamara Temple <tamara@tamaratemple.com>
- Time-stamp: <2012-06-21 02:22:57 tamara>
- Created: 2012-06-21
- Copyright (c) 2011 Tamara Temple Web Development
- License: GPLv3
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include <stdio.h>
- #include <time.h>
- int main(int argc, char *argv[])
- {
- struct tm tm;
- time_t t;
- time_t now;
- long left, weeks, days, hours, minutes, seconds;
- if (argc < 3) {
- printf("Usage: %s <format> <time_string>\n",argv[0]);
- return 1;
- }
- strptime(argv[2],argv[1],&tm);
- t=mktime(&tm);
- time(&now);
- left=(long) t - (long) now;
- if (left < 0) {
- printf("Deadline past.\n");
- return 2;
- }
- weeks = left/(60*60*24*7);
- days = (left%(60*60*24*7))/(60*60*24);
- hours = (left%(60*60*24))/(60*60);
- minutes = (left%(60*60))/(60);
- seconds = left%(60);
- printf("%d week(s), %d day(s), %d hour(s), and %d minute(s) left\n",weeks, days, hours, minutes, seconds);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement