LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 04-22-2004, 04:15 PM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
C built-in function for a Bash script


Bash script
now=`date "+%s"`
The above Bash script convert today 's date to a number.

1) Are the year, month, date, hour, minutes, seconds
and thousands of a second involved in this conversion ?

2) What is the mathematical formular for this conversion ?

3) What is the C built-in function for the above Bash
script ?

Last edited by Linh; 04-22-2004 at 04:17 PM.
 
Old 04-23-2004, 03:08 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
This is a 32 bit unsigned integer representing the number of seconds since what is called the epoch, January the 1st, 1970 UTC.
 
Old 04-23-2004, 04:26 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Re: C built-in function for a Bash script

Quote:
Originally posted by Linh
Bash script
now=`date "+%s"`
The above Bash script convert today 's date to a number.

1) Are the year, month, date, hour, minutes, seconds
and thousands of a second involved in this conversion ?
No, just seconds. But you can get the nanoseconds part of the time since the epoch with: date "+%N"
Or in C using the gettimeofday() function.

Quote:
2) What is the mathematical formular for this conversion ?
None actually. It's the other way around: The system (kernel) base format for the current time is in "number of seconds since the epoch". All other time formats are conversions from this.

Quote:
3) What is the C built-in function for the above Bash
script ?
That is the time() function. This example below does the same as: date "+%s".
Code:
#include <stdio.h>
#include <time.h>

int main()
{
	 printf("%ld\n", (long int)time(NULL));
	 return 0;
}

Last edited by Hko; 04-23-2004 at 04:29 AM.
 
Old 04-23-2004, 09:23 AM   #4
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
reply

jlliagre, and Hko. Thank you both for your help.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Split function (bash script) NiM Programming 11 03-10-2012 06:53 AM
warning: incompatible implicit declaration of built-in function ‘exit’ xzotech Programming 1 08-14-2005 05:43 AM
Bash Script Passing variable to Function nutthick Programming 2 02-02-2005 05:15 AM
search function (bash script) LYK Programming 2 05-27-2004 10:51 AM
question about strtok_r built-in function in C Linh Programming 4 05-14-2004 10:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration