473,371 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,371 software developers and data experts.

Using mktime()

Hey I was wondering if anyone could help me with some time code that I am using to determine if a year is a leap year or not. The code I have takes a given year, creates a time structure of the given year, and sets the date to 28th of Febuary, I then need to convert it using mktime(), add the amount of time to move to the next day, then reconvert it in order to take the month and determine whether it is a leap year or not by whether the month is Febuary of March. I have done the following code and have added and changed it several times, however, I cannot get it to work, any help would be much appreciated.

Expand|Select|Wrap|Line Numbers
  1. int isLibLeap(int year){
  3. int month;
  4. time_t rawtime;
  5. struct tm timeinfo;
  7. timeinfo->tm_year = year;
  8. timeinfo->tm_mon = 2;
  9. timeinfo->tm_mday = 28;
  11. mktime(timeinfo);
  13. timeinfo = timeinfo + 86400;
  15. gmtime(timeinfo);
  17. month = timeinfo->tm_mon;
  19. return month;
Nov 23 '07 #1
1 3467
9,208 Expert Mod 8TB
mktime() takes a struct tm argument and returns a time_t.

It is that time_t that you add the 86400 to and not the struct tm.

Then you use the time_t as the argument for gmtime to get the equivalent struct tm back.

Your code doesn't do that.

In fact, your code won't even compile.

Start with your first compiler error and fix that. Then rebuild. Then fix the first error, then rebuild, etc.

When you have no compile errors, your code will probably work.
Nov 24 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Bengt Richter | last post by:
Python 2.3.2 (#49, Oct 2 2003, 20:02:00) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.mktime((1969, 12, 31, 17, 0, 0, 0, 0, 0))...
by: Florian Quetting | last post by:
Hi, I'm getting mad with following problem: The code compiles, but I always get a segfault and I don't have any clue why. I can't see any differences in my way of calling mktime and others. ...
by: McBooCzech | last post by:
Hi, on Linux (Fedora FC4) and Python 2.4.1 I am trying to know the time delta in seconds between two times given in the HHMMSS format. My code looks like: import datetime, time...
by: KW | last post by:
Hi all, Appreciate if someone can help me out on this. Currently, I have a tm structure holding information of the UTC time, which is very likely to be in the past, meaning not the current...
by: John Hanley | last post by:
I created a function that breaks down a date into broken down time, I subtract a certain number of seconds from that, then use mktime() to recompute the calendar time. It works basically except...
by: JJ | last post by:
Here's the code. $link="http://xbox360cheat.org"; $close_date=$_POST; #last content change check if ($close_date == 0) $close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date...
by: John Hanley | last post by:
I am getting some inconsistencies with mktime(). I allocate memory for my struct tm early in my program, and assign only *some* of the member variables. t->tm_sec=s; t->tm_min=m;...
by: osward | last post by:
Hi everyone, Background 1. I have a table that consits 400+ rows of data and is growing by day. The table already has paging links at the bottom but I restricted to display rows of data only >=...
by: pedalpete | last post by:
I've got this error which keeps popping up, but I can't seem to figure out why. The error reads ' A non well formed numeric value encountered in filename on line <b>198</b>'. the lines...
by: Robert Latest | last post by:
Here's what happens on my Windows machine (Win XP / Cygwin) at work. I've googled a bit about this problem but only found references to instances where people referred to dates before the Epoch. ...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.