Converting timestamps to UTC in bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting timestamps to UTC in bash
# 1  
Old 03-04-2009
Converting timestamps to UTC in bash

Hello,

I am trying to figure out a way to convert the timestamps in a dataset from one timezone (which has daylight savings) to UTC.

Code:
2009-02-25 23:57:22,000D60727B89,221.16.86.23,SYSTEM1

What would be the best way to approach this?
# 2  
Old 03-04-2009
Use Perl's Time::Local module. This has 2 functions you can use...
  • timelocal will convert a local date/time into number of seconds into the epoch
  • gmtime will convert the number of seconds into the epoch into a formatted date/time in GMT, alias UTC
# 3  
Old 03-05-2009
I tried but got the following:

Quote:
Day '' out of range 1..31 at
This code taken from here

<CODE>
#-----------------------------
use Time::Local;
$TIME = timelocal($sec, $min, $hours, $mday, $mon, $year);
$TIME = timegm($sec, $min, $hours, $mday, $mon, $year);
#-----------------------------
# $hours, $minutes, and $seconds represent a time today,
# in the current time zone
use Time::Local;
$time = timelocal($seconds, $minutes, $hours, (localtime)[3,4,5]);
#-----------------------------
# $day is day in month (1-31)
# $month is month in year (1-12)
# $year is four-digit year e.g., 1967
# $hours, $minutes and $seconds represent UTC time
use Time::Local;
$time = timegm($seconds, $minutes, $hours, $day, $month-1, $year-1900);
#-----------------------------
</CODE>

This also gives me the same error.

Quote:
Day '' out of range 1..31 at ./UTC.pl line 4
Is their something I need to update in my perl installation to get this module to work properly?

thanks

Last edited by hazno; 03-05-2009 at 02:42 AM..
# 4  
Old 03-05-2009
What values are you feeding the routines? For your example (2009-02-25 23:57:22) they should be...
Code:
$TIME = timelocal(22, 57, 23, 25, 3, 109);

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting timestamp from PST to UTC

I need to convert the given datetime from PST to UTC, i gone through multiple forum examples but everywhere it mentioned about converting the server datetime. So could someone help me on this. I will be getting arguments for my script in the format of yyyymmddhh (eg:2015101004 - it will be pst),... (4 Replies)
Discussion started by: close2jay
4 Replies

2. 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

3. Shell Programming and Scripting

Converting awk script from bash to csh

I have the following script set up and working properly in bash. It basically copies a set of lines which match "AS1100002" from one file and replaces the same lines in another file. awk -vN=AS1100002* 'NR==FNR { if($1 ~ N)K=$0; next } { if($1 in K) $0=K; print }' $datadir/file1... (7 Replies)
Discussion started by: ncwxpanther
7 Replies

4. Shell Programming and Scripting

Converting from Linux bash (GNU) to Solaris script syntax errors

Original script written on CentOS 6.3 with GNU bash 4.1.2 Destination system is Solaris 9 with GNU bash 2.05 (not changeable by me) I have a script written on the linux side but now we need to provide a version to another site that "doesn't like linux". I've been going through changing the ] or... (13 Replies)
Discussion started by: oly_r
13 Replies

5. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: emdan
2 Replies

6. Shell Programming and Scripting

converting ksh to bash - typeset commands

Hi all, Am trying to convert a script written in ksh to a bash shell. At the moment, am stumped with the typeset -u command and I can't find an equivalent of it in bash. integer function is also not working as is the following if statement if ] && ]; then continue fi Is... (3 Replies)
Discussion started by: newbie_01
3 Replies

7. Shell Programming and Scripting

Bash script to copy timestamps of multiple files

Hi, I have a bunch of media files in a directory that have been converted (from MTS to MOV format), so my directory contains something like this: clip1.mts clip1.mov clip2.mts clip2.mov The problem is that the .mov files that have been created have the timestamps of the conversion task,... (2 Replies)
Discussion started by: Krakus
2 Replies

8. Shell Programming and Scripting

how to converting rows to columns, bash

I have in file these words: @fraza1 = rw @fraza2 = r @fraza3 = r @fraza4 = r @fraza5 = r @fraza1 = r @fraza6 = r @fraza7 = r @fraza2 = r @fraza8 = r @fraza9 = r ... I would like so that: ,rw,@fraza1 ,r,@fraza2 (2 Replies)
Discussion started by: patrykxes
2 Replies

9. UNIX for Dummies Questions & Answers

Converting bash shell to perl

Does anyone know how to convert this bash shell script to perl? for i in `ls -l *pgp` do `usr/bin/gpg --passphrase-fd 0 $i < .sunspot` done Thanks! Any help would be appreciated. I'm new to Linux and perl. (4 Replies)
Discussion started by: freak
4 Replies

10. 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
Login or Register to Ask a Question