gawk and strftime()


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting gawk and strftime()
# 1  
Old 05-07-2008
gawk and strftime()

Strange behaviour of the strftime() function from gawk (3.1.5):

Code:
$ awk 'BEGIN{print strftime("%T", 3600)}'
> 02:00:00

$ awk 'BEGIN{print strftime("%T", 0)}'
> 01:00:00

Obviously something with DST but I can not figure out why? To me 3600 epoch seconds remains 01:00, DST or not.

From the gawk man pages:
Code:
strftime([format [, timestamp]])
                 Formats  timestamp  according to the specification in format.  The timestamp should be of the same form
                 as returned by systime().  If timestamp is missing, the current time of day  is  used.   If  format  is
                 missing,  a  default format equivalent to the output of date(1) is used.  See the specification for the
                 strftime() function in ANSI C for the format conversions that are guaranteed to be available.   A  pub‐
                 lic-domain  version  of  strftime(3)  and a man page for it come with gawk; if that version was used to
                 build gawk, then all of the conversions described in that man page are available to gawk.

Any idea?
# 2  
Old 05-07-2008
DST is not UTC. If you mean METDST. It is one hour fast - exactly what you see. Plus you realize those values are for Dec 31 1969 - Jan 1 1970.

Midnight UTC is 1:00am DST. 1:00am UTC is 2:00am DST. What you see is correct.
Most systems are supposed to support the TZ variable. Play around with that
Code:
export TZ=MET-1METDST
date
export TZ=MET0
date
export TZ=ZZZ-19
date

Your gawk code should follow suit nicely.
# 3  
Old 05-07-2008
That was indeed the Time Zone that needed to be defined or canceled.

Code:
$ TZ=UTC awk 'BEGIN {print strftime("%T", 3600)}'
> 01:00:00

Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combining awk printf and print strftime command

I have a lines like below, captured from rrdtool fetch command, 1395295200 2.0629986254e+06 7.4634784967e+05 1395297000 2.0198121616e+06 6.8658888903e+05 1395298800 1.8787141122e+06 6.7482866452e+05 1395300600 1.7586118678e+06 6.7867977653e+05 1395302400 1.8222762151e+06 7.1301678859e+05I'm... (3 Replies)
Discussion started by: rk4k
3 Replies

2. UNIX for Advanced & Expert Users

[SOLVED] Making mktime/strftime available to mawk

I frequently use awk time functions and am switching some scripts over to mawk. I don't have the mktime or strftime functions in mawk, but it appears that there is a way, as explained here in "Time functions": Please only cut-and-past links to man pages from our man pages. So, simple... (10 Replies)
Discussion started by: treesloth
10 Replies

3. Shell Programming and Scripting

Help on awk strftime

cat file 41285.000034722223 41285.000567129631 41285.000069444446 41285.001122685186 41285.000092592592 41285.001620370371 41285.000138888892 41285.00340277778 41285.000185185185 41285.000405092593 41285.000196759262 41285.000856481478 41285.000208333331 41285.000717592593... (5 Replies)
Discussion started by: phpshell
5 Replies

4. Programming

TZ, localtime and strftime problem on AIX and Solaris

Hello all, I have the following code that seems to be misbehaving depending on the timezone setting (TZ Environment variable). It gives the correct value when TZ is in POSIX format and the wrong value when in OLSON format. #include <stdio.h> #include <stdlib.h> #include <time.h> #include... (6 Replies)
Discussion started by: biju64
6 Replies

5. Programming

strftime equivalent in c++

HI, i wish to convert a millsec value to a readable string format. the one option is to use strftime. However this is a bit costly (1-5 micros). is there a a faster way to do so with just string manipulation (Note i have the date object which has the time details but wish o avoid strftime) (2 Replies)
Discussion started by: wojtyla
2 Replies

6. Programming

strftime() creates memory leak

Hi, I am facing one strange situation while using strftime() to get current date and time in C. it leaks memory with %T strftime(L_StrDate,30,"%d-%b-%C%y %T", localtime((time_t *)&tv.tv_sec)) ; and when i use another option then no memory leak like strftime(L_StrDate,30,"%d-%b-%C%y ... (3 Replies)
Discussion started by: apskaushik
3 Replies

7. Shell Programming and Scripting

perl replace awk strftime

Hi Everyone i have a perl file below, one of the line is convert the pcho time to human readable format. $value=`awk 'BEGIN{print strftime("%c",1273236600)}' | tr -d '\n'`; if image, if i have lots of pcho time value in a file, if i use this awk, strftime, then tr -d to remove the \n,... (2 Replies)
Discussion started by: jimmy_y
2 Replies
Login or Register to Ask a Question