Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
03-03-2004, 02:39 PM
|
#1
|
Member
Registered: Oct 2002
Location: Michigan
Distribution: Slackware Linux 10.0
Posts: 289
Rep:
|
Starting day of month, month length
Does anyone have an algorithm that shows how to calculate the first day of the month, and the number of days? How would I know if a month started on Wednesday?
|
|
|
03-03-2004, 03:52 PM
|
#2
|
Member
Registered: Jul 2003
Location: VA Tech
Distribution: Mandrake 9.1
Posts: 73
Rep:
|
Re: Starting day of month, month length
Quote:
Originally posted by chrisk5527
Does anyone have an algorithm that shows how to calculate the first day of the month, and the number of days? How would I know if a month started on Wednesday?
|
I don't know what language you are using but Java's calendar class can do all that and more.
|
|
|
03-03-2004, 04:03 PM
|
#3
|
Member
Registered: May 2002
Posts: 964
Rep:
|
Code:
#include <time.h>
#include <stdlib.h>
/* parameters 1 - month as a number from 1 - 12 2 - year (from 1900 on) */
/* this does no error checking */
int main(int argc, char *argv[]){
int year=atoi(argv[2]);
int month=atoi(argv[1]);
char tmp[64]={'\0'};
struct tm my_tm;
time_t timer;
my_tm.tm_year=year-1900;
my_tm.tm_isdst=0;
my_tm.tm_sec=1;
my_tm.tm_min=0;
my_tm.tm_hour=0;
my_tm.tm_mon=month;
timer=mktime(&my_tm);
strftime(tmp,60,"%A is the first day of %B, %Y",&my_tm);
printf("%s \n",tmp);
}
/*
struct tm {
int tm_sec; /o second (0-61, allows for leap seconds) o/
int tm_min; /o minute (0-59) o/
int tm_hour; /o hour (0-23) o/
int tm_mday; /o day of the month (1-31) o/
int tm_mon; /o month (0-11) o/
int tm_year; /o years since 1900 o/
int tm_wday; /o day of the week (0-6) o/
int tm_yday; /o day of the year (0-365) o/
int tm_isdst; /o non-0 if daylight savings time is in effect o/
};
*/
|
|
|
All times are GMT -5. The time now is 09:21 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|