Sponsored Content
Top Forums Shell Programming and Scripting Converting date/time and generating offsets in bash script Post 302651031 by emdan on Monday 4th of June 2012 08:12:12 PM
Old 06-04-2012
Converting date/time and generating offsets in bash script

Hi all,
I need a script to do some date/time conversion. It should take as an input a particular time. It should then generates a series of offsets, in both hour:minute form and number of milliseconds elapsed.

For 03:00, for example, it should give back 04:02:07 (3727000ms*) 05:04:14 (7454000ms), 06:06:21 etc...

How would I go about doing this as a bash script? Ideally it would work on both Mac OS X and Linux (Ubuntu or Debian).

* (1hr * 60 minutes/hr *60 seconds/minute *1000ms/sec )+(2min*60 sec/min * 1000ms/sec)+(7sec*1000ms/sec) = (60*60*1000)+(2*60*1000)+(7*1000) = 3727000
 

10 More Discussions You Might Find Interesting

1. Tips and Tutorials

Simple date and time calulation in BASH

The GNU date command in full of goodies but not when it comes to calculate a date or time difference. Here is what I came up with after looking to more than one solution. Code should be self explaining. #!/bin/bash date2stamp () { date --utc --date "$1" +%s } stamp2date (){ ... (0 Replies)
Discussion started by: ripat
0 Replies

2. Shell Programming and Scripting

Converting bash script to csh

Hi, I'm a beginner in scripting and I recently wrote a bash script that would've worked fine until I realized it needed to be written in csh. Could someone please show me how to correctly change the syntax from bash to csh in this script? Any help will be greatly appreciated. I can provide more... (4 Replies)
Discussion started by: Kweekwom
4 Replies

3. Homework & Coursework Questions

Date comparison with 'string date having slashes and time zone' in Bash only

1. The problem statement, all variables and given/known data: I have standard web server log file. It contains different columns (like IP address, request result code, request type etc) including a date column with the format . I have developed a log analysis command line utility that displays... (1 Reply)
Discussion started by: TariqYousaf
1 Replies

4. Shell Programming and Scripting

Help converting date-time value to decimal

Hi I need help to do some calculation in script. I have a monitor program (munin) that I would like to log uptime information from a server. The script looks like this (not complete): #!/bin/sh # server_uptime ### Config Start # Reads the server parameters using the HTTP port with... (7 Replies)
Discussion started by: Jotne
7 Replies

5. Programming

Converting a user inputted date to epoch time

Hi all , I need to know how to convert a time stamp entered by the user to be converted to GMT/UTC(epoch time) using mktime() and gmtime() for exapample the input will be put in the form ptm.tm_sec = 0; ptm.tm_min = 59; ptm.tm_hour = 11; ptm.tm_mday = 20;... (2 Replies)
Discussion started by: ada
2 Replies

6. UNIX for Dummies Questions & Answers

Converting string date time to unix time in AWK

I'd like to convert a date string in the form of sun aug 19 09:03:10 EDT 2012, to unixtime timestamp using awk. I tried This is how each line of the file looks like, different date and time in this format Sun Aug 19 08:33:45 EDT 2012, user1(108.6.217.236) all: test on the 17th ... (2 Replies)
Discussion started by: bkkid
2 Replies

7. Shell Programming and Scripting

date time stamps in bash

I'm looking for a way to have the "date" command output the date in a specific format. I'm not familiar with the different ways to use the date command at all. i read up on it, but i dont get how to manipulate it. i know that i can get the date format to give me a format like: 2012-10-13... (6 Replies)
Discussion started by: SkySmart
6 Replies

8. Shell Programming and Scripting

Simple date and time calulation in BASH

There is a closed Thread: <url>Here will be the url to the original post once I have 5 posts in this forum...</url> But a small bug had found his way into this very cool and simple code. #!/bin/bash date2stamp () { date --utc --date "$1" +%s } stamp2date (){ date --utc --date... (2 Replies)
Discussion started by: frood
2 Replies

9. Shell Programming and Scripting

Converting macro to bash script

Gents, Please can you help me with this. When column 49 == 2 Before X 4714 14710 69445.00 19257.001 1218 12271 69596.00 19460.00 19478.001 X 4714 14710 69445.00 19257.001 1228 12292 69596.00 19480.00 19480.001 After X 4714 14710 69445.00 19257.001 1218... (1 Reply)
Discussion started by: jiam912
1 Replies

10. Shell Programming and Scripting

How to add missing date and time in a bash script?

Hi Again, I have a file that contains date and time for the past 2 hours. What i need is add missing date and time in a file. INPUT 2016-01-13 01:33 10 2016-01-13 01:31 10 2016-01-13 01:30 10 2016-01-13 01:29 10 2016-01-13 01:28 10 2016-01-13 01:27 10 2016-01-13 01:26 10 2016-01-13... (14 Replies)
Discussion started by: ernesto
14 Replies
LIBEXSLT(3)						     Library Functions Manual						       LIBEXSLT(3)

NAME
libexslt - extension library for XSLT SYNOPSIS
#include <libexslt/exslt.h> void exsltCommonRegister(void); void exsltDateRegister(void); void exsltDynRegister(void); void exsltFuncRegister(void); void exsltMathRegister(void); void exsltSetsRegister(void); void exsltStrRegister(void); void exsltRegisterAll(void); void exsltSaxonRegister(void); DESCRIPTION
The libexslt library is used to provide extensions to XSLT functions. These extensions come from the EXSLT project <http://www.exslt.org/> USAGE
To make use of these functions in XSLT the appropriate namespace must be defined on the xsl:stylesheet element. To enable support for them in libxslt(3) you must call the appropriate functions (listed in the SYNOPSIS section) to register the extensions. The xslt-config shell script can be used to obtain the necessary flags for the pre-processor and linker. The supported extensions are: COMMON Namespace: http://exslt.org/common See http://www.exslt.org/exsl/index.html for a description. node-set() convert the given RTF into a node-set. object-type() returns the type of the given argument. document Create multiple output documents. See http://www.exslt.org/exsl/elements/document/index.html MATH Namespace: http://exslt.org/math See http://www.exslt.org/math/index.html for a description. min() returns the minimum value of the given node-set max() returns the maximum value of the given node-set highest() returns the nodes in the node-set whose value is the maximum value for the node-set. lowest() returns the nodes in the node-set whose value is the minimum value for the node-set. constant() returns a number value of the given constant with the given precision. The constants are PI, E, SQRRT2, LN2, LN10, LOG2E, and SQRT1_2. random() returns a random number between 0 and 1 inclusive. abs() returns the absolute value of the argument. sqrt() returns the square root of the argument. power() returns the power base and power arguments. log() returns the natural log of the argument. sin() returns the sine of the argument. cos() returns the cosine of the argument. tan() returns the tangent of the argument. asin() returns the arc sine of the argument. acos() returns the arc cosine of the argument. atan() returns the arc tangent of the argument. atan2() returns the arc tangent function of the y/x arguments. exp() returns the exponential function of the argument. SETS Namespace: http://exslt.org/sets See http://www.exslt.org/set/index.html for a description. difference() returns the difference between the two given node-sets. intersection() returns a node-set of the nodes within both given node-sets. distinct() returns a node-set of all nodes in the first argument that are not in the seconds argument. has-same-node() returns TRUE if there is an intersection between the two given node-sets. leading() returns a node-set of all nodes in the first argument that precede the first node in the second argument. trailing() returns a node-set of all nodes in the first argument that follow the first node in the second argument. DATES and TIMES Namespace: http://exslt.org/dates-and-times See http://www.exslt.org/date/date.html for a description. date-time() returns the current date and time as a date/time string. date() returns the date specified in the given date/time string. time() returns the time specified in the date/time string given as the argument. year() returns the year of a date as a number. leap-year() returns true if the year given in a date is a leap year. month-in-year() returns the month of a date as a number. month-name() returns the full name of the month of a date. month-abbreviation() returns the abbreviation of the month of a date. week-in-year() returns the week of the year as a number. week-in-month() returns the week in a month of a date as a number. day-in-year() returns the month of a date as a number. day-in-month() returns the day of a date as a number. day-of-week-in-month() returns the day-of-the-week in a month of a date as a number. day-in-week() returns the day of the week given in a date as a number. day-name() returns the full name of the day of the week of a date. day-abbreviation() returns the abbreviation of the day of the week of a date. hour-in-day() returns the hour of the day as a number. minute-in-hour() returns the minute of the hour as a number. second-in-minute() returns the second of the minute as a number. seconds() returns the number of seconds specified by the argument string. add() returns the date/time resulting from adding a duration to a date/time. add-duration() returns the duration resulting from adding two given durations together. difference() returns the duration between the first date and the second date. duration() returns a duration string that represents the given number of seconds since 1970-01-01T00:00:00. STRINGS Namespace: http://exslt.org/strings See http://www.exslt.org/str/index.html for a description. tokenize() returns a node set of token elements, each containing one token from the string. padding() returns a string padded to a certain length. align() returns a string aligned within another string. concat() returns the concatenation of the string values of the nodes in that node set. FUNCTIONS Namespace: http://exslt.org/functions See http://www.exslt.org/func/index.html for a description. function declares an extension function. result returns the result of an extension function declared in function(). FILES
/usr/bin/xslt-config shell script giving pre-processor and linker flags. /usr/lib/libexslt.a static library /usr/lib/libexslt.so sharable library AUTHORS
Manual page by Heiko W. Rupp (hwr@pilhuhn.de) SEE ALSO
libxml(3), libxslt(3), xmllint(1) xsltproc(1), libxslt 04 November 2003 LIBEXSLT(3)
All times are GMT -4. The time now is 03:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy