Sponsored Content
Top Forums Shell Programming and Scripting how to convert date time to epoch time in solaris Post 302346545 by jim mcnamara on Saturday 22nd of August 2009 10:28:14 PM
Old 08-22-2009
The +%s format for date and date functions like strftime() is not defined by POSIX standards, oddly enough. So a lot of systems - Solaris being one - require the use of perl or ruby or python to do that. Or a complex shell function.

I think this is on the list of changes for the new C standards.

Date/time has always been a problem child because of locales, different calendars and so on.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to convert epoch time to readible format?

Hi, I would like to convert epoch time from the logs to readible fromat. How do I do it within shell? Thanks! (11 Replies)
Discussion started by: cin2000
11 Replies

2. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies

3. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

Hi guys, I know that this topic has been discuss numerous times, and I have search the net and this forum for it. However, non able to address the problem I faced so far. I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Discussion started by: DrivesMeCrazy
5 Replies

4. Shell Programming and Scripting

Convert epoch to human readable date & time format

Hello I have log file from solaris system which has date field converted by Java application using System.currentTimeMillis() function, example is 1280943608380 which equivalent to GMT: Wed, 04 Aug 2010 17:40:08 GMT. Now I need a function in shell script which will convert 1280943608380... (3 Replies)
Discussion started by: Yaminib
3 Replies

5. Shell Programming and Scripting

Shell script to convert epoch time to real time

Dear experts, I have an epoch time input file such as : - 1302451209564 1302483698948 1302485231072 1302490805383 1302519244700 1302492787481 1302505299145 1302506557022 1302532112140 1302501033105 1302511536485 1302512669550 I need the epoch time above to be converted into real... (4 Replies)
Discussion started by: aismann
4 Replies

6. Shell Programming and Scripting

Using awk or nawk to convert epoch time to date format

Looking for some help and usually when I do a search this site comes up. Hopefully someone can give me a little direction as to how to use one of these two commands to achieve what I'm trying to do. What am I trying to do? I need to take the time value in epoch format returned from the... (5 Replies)
Discussion started by: minigts
5 Replies

7. Shell Programming and Scripting

Convert to epoch time

how can i modify the following command to instead provide the epoch time of the interfaces file? perl -le 'print scalar localtime ((stat "/home/skysmart/interfaces"))' Tue Feb 19 03:44:52 2013 i'm hoping to get the equivalent of this command: stat --format=%Y /home/skysmart/interfaces ... (2 Replies)
Discussion started by: SkySmart
2 Replies

8. Shell Programming and Scripting

Convert epoch time to Julian date

Need assistance in converting an epoch time to Julian date To get epoch perl -e 'use Time::Local; print timelocal(1,5,2,12,10,2008), "\n"' (3 Replies)
Discussion started by: ajayram_arya
3 Replies

9. Shell Programming and Scripting

Convert a string to epoch time

Team, I am working on a shell script and i am extracting a date string in "SunOS server" with below format. Mon Jan 21 04:13:48 EST 2021 Can you please assist me the best way to convert the extracted string to epoch time like "date +%s" in Linux. Thanks in advance (1 Reply)
Discussion started by: Girish19
1 Replies

10. Shell Programming and Scripting

Convert Second Column Date Into EPOCH Time And Print Complete Row

Hello Team, I am stuck in getting the required output in the following case. Please help. My input file is aa|08/01/2016 bb|08/15/2016 I wish to convert the file into aa|epoch time bb|epoch time I am using following code: (3 Replies)
Discussion started by: angshuman
3 Replies
strftime(3C)						   Standard C Library Functions 					      strftime(3C)

NAME
strftime, cftime, ascftime - convert date and time to string SYNOPSIS
#include <time.h> size_t strftime(char *restrict s, size_t maxsize, const char *restrict format, const struct tm *restrict timeptr); int cftime(char *s, char *format, const time_t *clock); int ascftime(char *s, const char *format, const struct tm *timeptr); DESCRIPTION
The strftime(), ascftime(), and cftime() functions place bytes into the array pointed to by s as controlled by the string pointed to by format. The format string consists of zero or more conversion specifications and ordinary characters. A conversion specification consists of a '%' (percent) character and one or two terminating conversion characters that determine the conversion specification's behavior. All ordinary characters (including the terminating null byte) are copied unchanged into the array pointed to by s. If copying takes place between objects that overlap, the behavior is undefined. For strftime(), no more than maxsize bytes are placed into the array. If format is (char *)0, then the locale's default format is used. For strftime() the default format is the same as %c; for cftime() and ascftime() the default format is the same as %C. cftime() and ascftime() first try to use the value of the environment variable CFTIME, and if that is undefined or empty, the default format is used. Each conversion specification is replaced by appropriate characters as described in the following list. The appropriate characters are determined by the LC_TIME category of the program's locale and by the values contained in the structure pointed to by timeptr for strf- time() and ascftime(), and by the time represented by clock for cftime(). %% Same as %. %a Locale's abbreviated weekday name. %A Locale's full weekday name. %b Locale's abbreviated month name. %B Locale's full month name. Default %c Locale's appropriate date and time represented as: %a %b %d %H:%M:%S %Y This is the default behavior as well as standard-conforming behavior for standards first supported by releases prior to Solaris 2.4. See standards(5). Standard conforming %c Locale's appropriate date and time represented as: %a %b %e %H:%M:%S %Y This is standard-conforming behavior for standards first supported by Solaris 2.4 through Solaris 10. Default %C Locale's date and time representation as produced by date(1). This is the default behavior as well as standard-conforming behavior for standards first supported by releases prior to Solaris 2.4. Standard conforming %C Century number (the year divided by 100 and truncated to an integer as a decimal number [01,99]). This is standard-conforming behavior for standards first supported by Solaris 2.4 through Solaris 10. %d Day of month [01,31]. %D Date as %m/%d/%y. %e Day of month [1,31]; single digits are preceded by a space. %F Equivalent to %Y-%m-%d (the ISO 8601:2000 standard date format). %g Week-based year within century [00,99]. %G Week-based year, including the century [0000,9999]. %h Locale's abbreviated month name. %H Hour (24-hour clock) [00,23]. %I Hour (12-hour clock) [01,12]. %j Day number of year [001,366]. %k Hour (24-hour clock) [0,23]; single digits are preceded by a space. %l Hour (12-hour clock) [1,12]; single digits are preceded by a space. %m Month number [01,12]. %M Minute [00,59]. %n Insert a NEWLINE. %p Locale's equivalent of either a.m. or p.m. %r Appropriate time representation in 12-hour clock format with %p. %R Time as %H:%M. %S Seconds [00,60]; the range of values is [00,60] rather than [00,59] to allow for the occasional leap second. %t Insert a TAB. %T Time as %H:%M:%S. %u Weekday as a decimal number [1,7], with 1 representing Monday. See NOTES below. %U Week number of year as a decimal number [00,53], with Sunday as the first day of week 1. %V The ISO 8601 week number as a decimal number [01,53]. In the ISO 8601 week-based system, weeks begin on a Monday and week 1 of the year is the week that includes both January 4th and the first Thursday of the year. If the first Monday of January is the 2nd, 3rd, or 4th, the preceding days are part of the last week of the preceding year. See NOTES below. %w Weekday as a decimal number [0,6], with 0 representing Sunday. %W Week number of year as a decimal number [00,53], with Monday as the first day of week 1. %x Locale's appropriate date representation. %X Locale's appropriate time representation. %y Year within century [00,99]. %Y Year, including the century (for example 1993). %z Replaced by offset from UTC in ISO 8601:2000 standard format (+hhmm or -hhmm), or by no characters if no time zone is determinable. For example, "-0430" means 4 hours 30 minutes behind UTC (west of Greenwich). If tm_isdst is zero, the standard time offset is used. If tm_isdst is greater than zero, the daylight savings time offset if used. If tm_isdst is negative, no characters are returned. %Z Time zone name or abbreviation, or no bytes if no time zone information exists. If a conversion specification does not correspond to any of the above or to any of the modified conversion specifications listed below, the behavior is undefined and 0 is returned. The difference between %U and %W (and also between modified conversion specifications %OU and %OW) lies in which day is counted as the first of the week. Week number 1 is the first week in January starting with a Sunday for %U or a Monday for %W. Week number 0 contains those days before the first Sunday or Monday in January for %U and %W, respectively. Modified Conversion Specifications Some conversion specifications can be modified by the E and O modifiers to indicate that an alternate format or specification should be used rather than the one normally used by the unmodified conversion specification. If the alternate format or specification does not exist in the current locale, the behavior will be as if the unmodified specification were used. %Ec Locale's alternate appropriate date and time representation. %EC Name of the base year (period) in the locale's alternate representation. %Eg Offset from %EC of the week-based year in the locale's alternative representation. %EG Full alternative representation of the week-based year. %Ex Locale's alternate date representation. %EX Locale's alternate time representation. %Ey Offset from %EC (year only) in the locale's alternate representation. %EY Full alternate year representation. %Od Day of the month using the locale's alternate numeric symbols. %Oe Same as %Od. %Og Week-based year (offset from %C) in the locale's alternate representation and using the locale's alternate numeric symbols. %OH Hour (24-hour clock) using the locale's alternate numeric symbols. %OI Hour (12-hour clock) using the locale's alternate numeric symbols. %Om Month using the locale's alternate numeric symbols. %OM Minutes using the locale's alternate numeric symbols. %OS Seconds using the locale's alternate numeric symbols. %Ou Weekday as a number in the locale's alternate numeric symbols. %OU Week number of the year (Sunday as the first day of the week) using the locale's alternate numeric symbols. %Ow Number of the weekday (Sunday=0) using the locale's alternate numeric symbols. %OW Week number of the year (Monday as the first day of the week) using the locale's alternate numeric symbols. %Oy Year (offset from %C) in the locale's alternate representation and using the locale's alternate numeric symbols. Selecting the Output Language By default, the output of strftime(), cftime(), and ascftime() appear in U.S. English. The user can request that the output of strftime(), cftime(), or ascftime() be in a specific language by setting the LC_TIME category using setlocale(). Time Zone Local time zone information is used as though tzset(3C) were called. RETURN VALUES
The strftime(), cftime(), and ascftime() functions return the number of characters placed into the array pointed to by s, not including the terminating null character. If the total number of resulting characters including the terminating null character is more than maxsize, strftime() returns 0 and the contents of the array are indeterminate. EXAMPLES
Example 1 An example of the strftime() function. The following example illustrates the use of strftime() for the POSIX locale. It shows what the string in str would look like if the struc- ture pointed to by tmptr contains the values corresponding to Thursday, August 28, 1986 at 12:44:36. strftime (str, strsize, "%A %b %d %j", tmptr) This results in str containing "Thursday Aug 28 240". ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ |Interface Stability |Committed | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ |Standard |See below. | +-----------------------------+-----------------------------+ For strftime(), see standards(5). SEE ALSO
date(1), ctime(3C), mktime(3C), setlocale(3C), strptime(3C), tzset(3C), TIMEZONE(4), zoneinfo(4), attributes(5), environ(5), standards(5) NOTES
The conversion specification for %V was changed in the Solaris 7 release. This change was based on the public review draft of the ISO C9x standard at that time. Previously, the specification stated that if the week containing 1 January had fewer than four days in the new year, it became week 53 of the previous year. The ISO C9x standard committee subsequently recognized that that specification had been incorrect. The conversion specifications for %g, %G, %Eg, %EG, and %Og were added in the Solaris 7 release. This change was based on the public review draft of the ISO C9x standard at that time. These specifications are evolving. If the ISO C9x standard is finalized with a differ- ent conclusion, these specifications will change to conform to the ISO C9x standard decision. The conversion specification for %u was changed in the Solaris 8 release. This change was based on the XPG4 specification. If using the %Z specifier and zoneinfo timezones and if the input date is outside the range 20:45:52 UTC, December 13, 1901 to 03:14:07 UTC, January 19, 2038, the timezone name may not be correct. SunOS 5.11 5 Sep 2006 strftime(3C)
All times are GMT -4. The time now is 09:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy