views:

1428

answers:

1

Hi! Is there an opportunity to convert a string into a date in bash? For example: I have a time format: "%Y-%m-%dS%H:%M:%S". An example of such string is "2009-06-24S12:34:56". I need to convert this string into a date (unix timestamp) in bash. How can I do this?

+1  A: 

Use

date --utc --date "<input string>" +%s
Matthew Iselin
I am on solaris 10. This does not work on it. Sorry, I should have mentioned the OS.date: illegal option -- utcdate: illegal option -- dateusage: date [-u] mmddHHMM[[cc]yy][.SS] date [-u] [+format] date -a [-]sss[.fff]
Markus
Ah, Solaris. If you do a quick Google search you'll find a lot of people struggling with the same problem: Solaris' date program isn't nearly as powerful as the others out there. You could probably get the same results using Perl or a C program though.
Matthew Iselin
And Perl should also be available on almost any Solaris box.
Aaron Digulla