Sponsored Content
Top Forums Programming may be simple but i don't know -- Print current date from C program Post 15525 by Perderabo on Friday 15th of February 2002 08:57:30 AM
Old 02-15-2002
Here is my test program:
Code:
#include<iostream.h>
#include<time.h>
main()
{
        time_t tt;
        struct tm *tod;
        time(&tt);
        tod=localtime(&tt);
        cout << tod->tm_mon +1 << "/" << tod->tm_mday << "/"
             << tod->tm_year << endl ;
        exit(0);
}

Give it a try. I am getting 2/15/102 without doing anything more. Internally the library will at my TZ environment variable but that's the only other thing that can affect the output that I know of.

And by the way, I tested on a Sun. What system are you using?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to subtract 2 hours from 'date' in shell ( /bin/sh ) script ?

I write a sh script that zip and copy to tape all files that older then 2 hours. 1. The way I choose is - touch a file with "now - 2 hours", then use fine with '! -newer' 2. Do you have any other idea to do it ? tnx. (1 Reply)
Discussion started by: yairon
1 Replies

2. UNIX for Dummies Questions & Answers

Don't Know to Rebuild Linux Kernel(URGENT)

Hello. I'm installing Oracle8i on Red Hat Linux Server 7.0. The Oracle documentation has some preinstallation request to be carried before installing the Oracle software. It asks to modify some SEMAPHORE & SHARED MEMORY values in to a specified file. And finally after updating this values it... (2 Replies)
Discussion started by: S.Vishwanath
2 Replies

3. UNIX for Dummies Questions & Answers

Don't hate me because I'm stupid...

Hi all, I don't know the first thing about Unix, but I would like to learn. I would like to know what the difference between Linux and Unix is, and where I can obtain a copy of either. Thanks :o (8 Replies)
Discussion started by: ThisIsNewToMe
8 Replies

4. Programming

a very simple question (but i don't know)

how to write a program that receive a string from keyboard and then print it out. i write a program: main() { char str; gets(str); printf(str); } but when i compile it, the system said something like "new line is not last charicter" and sometime the system said "a3.c is up to date"... (1 Reply)
Discussion started by: dell9
1 Replies

5. UNIX Desktop Questions & Answers

Genome Startmenu crashed why I don't Know ??

what I have to do ? (1 Reply)
Discussion started by: atiato
1 Replies

6. UNIX for Dummies Questions & Answers

I don't know where to start

I have been in computers for 30 years and know everything about MS, but nothing about anything else. Been developping websites (inter alia) running on MS servers using ASP's and vbScripts which apparently does not work under Unix. My own website is being hosted on a Unix server and I need to... (4 Replies)
Discussion started by: paul@cascom
4 Replies

7. UNIX for Dummies Questions & Answers

How a program to convert '|' delimited file into excel?

Hi All, I want to convert a '|' delimited file to excel file. I want it is an automated process (this means I need not to open excel, import and choose '|' delimited, then ... to generate an excel) I need to use a scripts or proram to convert the file. Do any one have this tools? A... (11 Replies)
Discussion started by: wilsonchan1000
11 Replies

8. UNIX for Dummies Questions & Answers

awk to print current date?

List, I want to print the first line of my text file (say "me you"), preceded by the current date/time. Something like (pseudo code): awk '{print date,$1}' I don't have a lot of awk knowledge (understatement), so forgive me if the answer is obvious... (3 Replies)
Discussion started by: philipz
3 Replies

9. UNIX for Dummies Questions & Answers

print all dates 100 days from current date

can anyone please suggest me on ideas to write a script which has to go back to 100 days from 'current date' and print the date of each day starting from 100th day to current day. (korn shell please) Thanks Pavan (5 Replies)
Discussion started by: pavan_test
5 Replies

10. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies
LOCALTIME(3)								 1							      LOCALTIME(3)

localtime - Get the local time

SYNOPSIS
array localtime ([int $timestamp = time()], [bool $is_associative = false]) DESCRIPTION
The localtime(3) function returns an array identical to that of the structure returned by the C function call. PARAMETERS
o $timestamp - The optional $timestamp parameter is an integer Unix timestamp that defaults to the current local time if a $timestamp is not given. In other words, it defaults to the value of time(3). o $is_associative - If set to FALSE or not supplied then the array is returned as a regular, numerically indexed array. If the argument is set to TRUE then localtime(3) returns an associative array containing all the different elements of the structure returned by the C func- tion call to localtime. The names of the different keys of the associative array are as follows: o "tm_sec" - seconds, 0 to 59 o "tm_min" - minutes, 0 to 59 o "tm_hour" - hours, 0 to 23 o "tm_mday" - day of the month, 1 to 31 o "tm_mon" - month of the year, 0 (Jan) to 11 (Dec) o "tm_year" - years since 1900 o "tm_wday" - day of the week, 0 (Sun) to 6 (Sat) o "tm_yday" - day of the year, 0 to 365 o "tm_isdst" - is daylight savings time in effect? Positive if yes, 0 if not, negative if unknown. ERRORS
/EXCEPTIONS Every call to a date/time function will generate a E_NOTICE if the time zone is not valid, and/or a E_STRICT or E_WARNING message if using the system settings or the $TZ environment variable. See also date_default_timezone_set(3) CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.1.0 | | | | | | | Now issues the E_STRICT and E_NOTICE time zone | | | errors. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 localtime(3) example <?php $localtime = localtime(); $localtime_assoc = localtime(time(), true); print_r($localtime); print_r($localtime_assoc); ?> The above example will output something similar to: Array ( [0] => 24 [1] => 3 [2] => 19 [3] => 3 [4] => 3 [5] => 105 [6] => 0 [7] => 92 [8] => 1 ) Array ( [tm_sec] => 24 [tm_min] => 3 [tm_hour] => 19 [tm_mday] => 3 [tm_mon] => 3 [tm_year] => 105 [tm_wday] => 0 [tm_yday] => 92 [tm_isdst] => 1 ) SEE ALSO
getdate(3). PHP Documentation Group LOCALTIME(3)
All times are GMT -4. The time now is 03:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy