LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-04-2008, 09:51 AM   #1
zest n zeal
LQ Newbie
 
Registered: May 2007
Posts: 18

Rep: Reputation: 0
How do I get `date` to accept UCT input?


Hi there,

Date seems to take all types of input but I cannot find a way for it to accept UCT input?

so for instance although I can put in
[HTML]
zeal$ date --date "10/11/2001 12:34" '+%s'
1002800040 [/HTML]

how can I input 1002800040 and get another date format back?

Many thanx in advance,

Adam
 
Old 03-04-2008, 12:28 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
By not explicitly asking it to output seconds since epoch?
Get rid of the "+%s"

Use -u

Cheers,
Tink
 
Old 03-04-2008, 12:47 PM   #3
zest n zeal
LQ Newbie
 
Registered: May 2007
Posts: 18

Original Poster
Rep: Reputation: 0
No, I'm sorry I am misunderstood, imagine I only have a date in seconds from epoch and I want to know what actual date and time that was. i.e., something like this:

[HTML]zeal$ date 1002800040
Tues Oct 11 12:34:00 GMT 2001
[/HTML]

Adam
 
Old 03-04-2008, 03:21 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Oh... I don't think you can (easily). Use perl.
http://pleac.sourceforge.net/pleac_p...sandtimes.html



Cheers,
Tink
 
Old 03-04-2008, 04:38 PM   #5
zest n zeal
LQ Newbie
 
Registered: May 2007
Posts: 18

Original Poster
Rep: Reputation: 0
thanx anyhow

at least my questions are getting less dumb when the answer includes "not easily"

thnx
 
Old 03-04-2008, 05:20 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Well, I HAVE seen date-manipulation functions for that kind of thing in pure
bourne-shell script. But it's ugly and convoluted. If you search for
"bourne or bash date epoch" on google you will likely find a way of doing
it w/o perl. But perl in this case is a) smaller, b) more readable and
c) way faster ....


Cheers,
Tink
 
Old 03-04-2008, 05:42 PM   #7
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 75
Quote:
Originally Posted by Tinkster View Post
Oh... I don't think you can (easily)
Well, if you are using GNU date, you can do it easily:
Code:
$ date -d '@1002800040'
Thu Oct 11 07:34:00 EDT 2001
 
Old 03-04-2008, 06:07 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
An undocumented feature!
$ date --version
date (GNU coreutils) 6.9

Man page doesn't mention it.


Cheers,
Tink
 
Old 03-04-2008, 07:29 PM   #9
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 75
Quote:
Originally Posted by Tinkster View Post
An undocumented feature!
While it is documented somewhere, this is one of the GNU utilities which “feels backward” when compared to say the BSD version (at least IMO). IMO, many of the GNU utilities have better features than their BSD or Solaris counterparts, but in this case the BSD version of date allows you direct access to strptime() where you can specify the format exactly, whereas the GNU version uses cryptic, poorly-documented, and inflexible syntax.

Because of the very broad differences between implementations, the standard date is very ill-featured compared to either.
 
Old 03-04-2008, 07:44 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
I guess in this case GNUs preference of info over man shows quite clearly,
once again ... :/ ... this indeed part of the info-pages.


Cheers,
Tink
 
Old 03-05-2008, 04:30 AM   #11
zest n zeal
LQ Newbie
 
Registered: May 2007
Posts: 18

Original Poster
Rep: Reputation: 0
Sorted

Many thanks to you both

Adam
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to accept input with bash shell? Guess Programming 6 10-04-2007 08:06 PM
accept input escape new line monil Programming 12 03-18-2005 01:10 PM
Can't get any output from my mic. Won't accept input. Please help Fear58 Linux - Hardware 1 07-07-2004 12:42 AM
RH 8.0 installer wont accept keyboard input exitsfunnel Linux - General 1 05-27-2003 11:18 AM
RH 8.0 installer won't accept keyboard input exitsfunnel Linux - Software 2 05-27-2003 07:20 AM


All times are GMT -5. The time now is 08:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration