Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get the current timestamp? 1

Status
Not open for further replies.

AlbertAguirre

Programmer
Nov 21, 2001
273
US
I need to display the current date and time in the unix timestamp format.
How do I do this at the command line?
 
Wow. That helps. Thank you.

I guess its not possible to do this with a standard unix command like date?
 
if you have a C compiler you can create your own:

source file udate.c
Code:
#include <time.h>
#include <stdio.h>

# udate.c - print seconds since "the epoch"

main ()
{
  time_t nowsec;

  nowsec = time (&nowsec);

  printf ("%ld\n", (long)nowsec);
}

cc udate.c -o udate
and use the command as

udate



otherwise create a file named udate.pl

Code:
#!/usr/bin/perl

# udate.pl - print seconds since "the epoch"

print scalar time, "\n";

Note: the first line may need altering - look and see where your perl executable lives.

and use the command as

udate.pl

or whatever other name you choose - doesn't have to use the .pl suffix, but it helps in identifying the contents...



HTH,

p5wizard
 
I forgot - you have to make the perl script executable:

chmod 755 udate.pl

in order to use it as a command.

HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top