Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Standard C, C++

Reply
 
LinkBack Thread Tools Display Modes
Old 10-13-2004, 03:00 AM   #1 (permalink)
if13121
Registered User
 
if13121's Avatar
 
Join Date: Oct 2004
Location: Bandung,Indonesia
Posts: 16
if13121 is on a distinguished road
problems get local time using sys/time.h

Dear All, Please help me.
i can't run this program under linux.
I got :
calljam.c:19: warning: assignment makes pointer from integer without a cast
calljam.c:20: dereferencing pointer to incomplete type
...
...
It works under Windows but when i print L.DD, L.MM, L.YYYY it return number such 121367232732
the program:
Code:
/* File : calljam.c */ 
#include <sys/time.h> 
#include <stdio.h> 
typedef struct
{
  int DD;
  int MM;
  int YYYY;
}date;

int main () 
{ 
  date L;	
  time_t now; 
  struct tm *T; 
 
  now = time(NULL); 
  T = localtime (&now); 
  printf ("Jam = %d:%d:%d\n ", 
          T->tm_hour, T->tm_min, T->tm_sec); 
  printf ("Date = %d-%d-%d\n ",
          T->tm_mday, T->tm_mon + 1, T->tm_year+1900); 
  printf ("local time %s\n", asctime (T)); 
  L.DD   = T->tm_mday;
  L.MM   = T->tm_mon + 1;
  L.YYYY = T->tm_year + 1900;
  printf ("Date = %d-%d-%d\n ", L.DD, L.MM, L.YYYY); 
  return 0; 
}

Last edited by redhead; 10-13-2004 at 06:41 AM.
if13121 is offline   Reply With Quote
Old 10-13-2004, 06:37 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
try changing
#include <sys/time.h>
to
#include <time.h>

sys/time.h under *nix dosn't have anything called localtime() or time() it only has time-structures defined.

And I took teh liberty to reformat your code with adding [code ] [/code ] tags, aswell as moving some of the definitions around, to make it more readable...
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 10-14-2004, 09:19 PM   #3 (permalink)
if13121
Registered User
 
if13121's Avatar
 
Join Date: Oct 2004
Location: Bandung,Indonesia
Posts: 16
if13121 is on a distinguished road
thank u
if13121 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using IsDate( ) to check for a Time value shs MS Technologies ( ASP, VB, C#, .NET ) 1 09-09-2004 12:03 PM
network time synchronisation in java bossebo Java 1 06-21-2004 05:17 PM
Adjusting date() function for time zones Epsilon PHP 1 02-27-2004 02:55 AM


All times are GMT -8. The time now is 09:22 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting