![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compare date from db2 table to yesterday's Unix system date | sasaliasim | Shell Programming and Scripting | 9 | 12-01-2008 11:37 PM |
| Perl: Extracting date from file name and comparing with current date | MKNENI | Shell Programming and Scripting | 4 | 03-26-2008 04:01 PM |
| date issue-find prevoius date in a patricular format | bsandeep_80 | UNIX for Advanced & Expert Users | 3 | 11-15-2007 08:42 PM |
| Changing Creation Date to a Prespecified Date of a File In Unix | monkfan | UNIX for Dummies Questions & Answers | 4 | 11-28-2006 07:15 AM |
| a simple way of converting a date in seconds to normal date | travian | HP-UX | 2 | 11-23-2006 12:25 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hello,
How do i translate datevalues in unix to normal dates. and how do i translate normal dates in to datevalues. I'm using the unix-date. Sample: 1067949360 to 4-11-03 12:36 and 4-11-03 12:36 to 1067949360 I want to built a script with a question to the user: give in date the input will be 4-11-03 . I have to translate it to 1067940000 and run a script. Afther that i'll want to print a rapport. Quest what ?? A translation from 1067949360 to 4-11-03 12:36 Help. Sorry for the bad englisch (just someone from holland) ![]() |
|
||||
|
Code:
#! /usr/bin/perl -w use Time::Local; $sec=0; $min=36; $hour=12; $mday=5; $mon=11; $year=103; #4-11-03 12:36 ### use this date and time for example $time = timelocal($sec,$min,$hour,$mday,$mon,$year); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time); print "DATE:$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst\n"; print "TIME: $time\n"; ~ "test.pl" 73 lines, 1946 characters [qgatu003]/export/home/mxdooley/mbi_script$./test.pl DATE:0,36,12,5,11,103,5,338,0 TIME: 1070649360 |
|
|||||
|
You can also use Python to do the conversion as
shown in the following example. - Finnbarr import os, sys, datetime import time usage = "Usage: %s [s | d] value" %os.path.basename(sys.argv[0]) try: mode = sys.argv[1] value = sys.argv[2] except IndexError: print usage; sys.exit(0) if (mode != "s" and mode != "d"): print usage; sys.exit(1); if (mode == "s"): fpm=time.strptime(value, "%d-%m-%y %H:%M") print "Date --> Epoch: ", int(time.mktime(fpm)) else: print "Epoch --> Date: ", datetime.datetime.fromtimestamp(float(value)).strftime("%d-%m-%y %H:%M") |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|