Sponsored Content
Top Forums UNIX for Dummies Questions & Answers formatting date for different locales Post 302133313 by Aeon on Thursday 23rd of August 2007 12:39:26 AM
Old 08-23-2007
Question date conversions at runtime

Quote:
Originally Posted by jim mcnamara
What locale for LC_TIME? And to answer that we need to know which UNIX you're using.
Plus, you do know LC_TIME can affect things like the first day of the week as well.

Do you know about setlocale()?

If you give us exact specifications it would help a lot.
I need to do date conversions between german and french at runtime.

mine is red hat linux 9
am a beginner & I ve a little knowledge about setlocale and LC_TIME.
I tried a sample helloworld L10N program through gettext utility.

Thanks for the quick reply jim,

Aeon.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Formatting date

i need date in the following format December 14, 2005. With date +"%b %d, %Y" command i am getting the following output :- Dec 14, 2005. can anyone pls tell me how to get the full month name (2 Replies)
Discussion started by: radhika03
2 Replies

2. Shell Programming and Scripting

date formatting

Date format MM/DD/YYYY required is YYYYMMDD, I tried using sed but could not get it any help please. (4 Replies)
Discussion started by: mgirinath
4 Replies

3. UNIX for Dummies Questions & Answers

Date formatting

Running bash how do I input the date in the command line like 3/20/90 and get an output formmated like March, 20 1990. (8 Replies)
Discussion started by: knc9233
8 Replies

4. Shell Programming and Scripting

date formatting

Hi i need to have the date in the format like dd-mon-yyyy my script goes like this #!/usr/bin/bash for f in /space/can /home/lbs/current/externalcdrbackup/L_CDR_Configuration/1/200903122* ; do awk '{sum++;}END{for(i in sum) {print d,h,m,i, sum}}' "d=$(date +'%m-%d-%Y')" "h=$(date +'%H')"... (8 Replies)
Discussion started by: aemunathan
8 Replies

5. OS X (Apple)

Date Formatting, etc.

Hi - I'm using GeekTool to customize my desktop in OS X 10.5.8 I'm a complete novice as far as UNIX commands, just know enough to be dangerous. I have a command entered as a Shell to display my events from iCal: This makes my events show something like this: While this is... (1 Reply)
Discussion started by: patricksprague
1 Replies

6. Shell Programming and Scripting

Formatting a date

Hi, the date value retrieved by a parameter from the table is of the format dd/mm/yyyy. please let me know how to convert this to YYYYMMDD using sed thanks (4 Replies)
Discussion started by: swasid
4 Replies

7. Shell Programming and Scripting

Formatting date

Hi all Y=`date +'%Y'` M=`date +'%m'` D=`date +'%d'` if && ;then yesterday=$Y$M`expr $D + 30` echo $yesterday else if && ; then yesterday=$Y$M`expr $D + 29` echo $yesterday else if ; then yesterday=$Y$M`expr $D + 27` echo $yesterday else yesterday=$Y$M`expr $D - 1` echo... (8 Replies)
Discussion started by: ultimatix
8 Replies

8. Shell Programming and Scripting

Date formatting in AIX

Can you help in formating the date command in aix to get the following format Oct 11 21:52 Fri Oct 11 21:52:01 PDT 2013 Required output: Oct 11 21:52 Fri Oct 11 21:52:01 PDT 2013 (1 Reply)
Discussion started by: chandu123
1 Replies

9. UNIX for Dummies Questions & Answers

Need Date Formatting help

Hi, How can i store the date + time from the output of the ls command in loop in a variable date1? -rw-rw---- 1 user1 admin 500002 Jan 2 21:24 P002607.cssI then want to convert Jan 2 21:24 to this date format 2014-01-02 21:24:00 and save it in date2 variable. Then i would like to add... (1 Reply)
Discussion started by: mohtashims
1 Replies

10. Shell Programming and Scripting

UNIX Date Formatting

Hi I have a shell variable storing DATE in YYYY-MM-DD format is there a way i extract required field say only DD Also, would be great if there is a way which could take date format as well so that code is generic for any date format eg DDMMYYYY or DD/MM/YYYY or YYYY/MM/DD etc. Thanks (4 Replies)
Discussion started by: skyineyes
4 Replies
getdate(3)						     Library Functions Manual							getdate(3)

NAME
getdate, getdate_r - Convert formatted string into time/date structure LIBRARY
Standard C Library (libc.so, libc.a) SYNOPSIS
#include<time.h> struct tm *getdate( const char *string); The following function declarations do not conform to current standards and are supported only for backward compatibility: #include<time.h> struct tm *getdate( char *string); struct tm *getdate_r( char *string, struct tm *ptr, int *getdate_err); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: getdate(): XPG4-UNIX Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Points to the user-definable date and/or time specifications. Points to a time structure. Points to the local getdate_err. DESCRIPTION
The getdate() function fills a struct tm based on a combination of the supplied string argument and the template file of allowable formats for that argument. The template file is obtained from the DATEMSK environment variable. As the pathname is passed to fopen(), it must either be a fully qual- ified pathname, or must refer to a file in the current directory whenever getdate() is called. The template file is read line by line, and each line is parsed against the argument string in an attempt to make a match. All comparisons are made without regard to case. A matching template line will result in a valid struct tm being filled in and returned. In the event that no match is found, an error is returned in getdate_err. Each line of the template file provides a possible format to match against the input string. The format is specified by combining special time/date specifier characters preceded by % to indicate the particular time/date functions desired. The external variable or macro getdate_err is used by getdate() to return error values. The following field descriptors are supported: Literal % character Abbreviated weekday name Full weekday name Abbreviated month name Full month name Locale's appropriate date and time representation Day of month: 1 through 31, with optional leading zero Date string formatted as %m/%d/%y Same as %d. Abbreviated month name **Same as %b.???????????? Hour: 00 through 23 Hour: 01 through 12 Month number: 01 through 12 Minute: 00 through 59 Literal newline character Locale's equivalent to AM or PM string Locale's appropriate representation of time (formatted as %I:%M:%S %p in the POSIX locale). Time formatted as %H:%M Seconds: 00 through 61. Leap seconds, through the use of algo- rithms, are allowed but are not predictable. Whitespace up through literal tab Locale's appropriate representation of time in AM and PM notation (%H:%M:%S in the POSIX locale). Weekday number: 0 (Sunday) through 6 (Saturday) Date formatted as specified by locale Time for- matted as specified by locale Year (excluding century). When a century is not otherwise specified (for example, with %C), values in the range 69-99 refer to years in the twentieth century (1969 to 1999, inclusive); values in the range 00-68 refer to years in the twenty-first century (2000 to 2068, inclusive). Year (including century) as ccyy (for example, 1996) Time zone name or no characters if no time zone exists. If the time zone supplied by %Z is not the time zone that getdate() expects, an invalid input specification error will result. The getdate() function calculates an expected time zone based on information supplied to the function (such as the hour, day, and month). If the string parameter specifies the date and time incompletely, the following rules apply: If %Z is being scanned, getdate() initializes the broken-down time to be the current time in the scanned time zone. Otherwise, it initializes the broken-down time based on the current local time as if localtime() had been called. If a year is specified alone, the remainder of the date defaults to January 1. If a month is specified without a day of the month or day of the week, the next month matching that month is used, starting with the current month. The year advances if the matching month is beyond the current year. The day of the month defaults to the 1st. If a day of the week is specified, the next date matching that day is used, starting with the current day. The month advances if the matching day is beyond the end of the current month. The year may advance similarly. In cases 2, 3 and 4, the time of day is not altered unless it is explicitly specified. If time alone is specified, the date defaults to today (the current day), unless the time specified is earlier than now (the current time), in which case the date defaults to tomorrow. RETURN VALUES
Upon successful completion, the getdate() function returns a pointer to a struct tm. Otherwise, it returns a null pointer and the external variable getdate_err is set to indicate the error. Upon successful completion, the getdate_r function returns pointer struct tm. Otherwise, NULL is returned and the int value pointed to by the getdate_err pointer is set to indicate the error. ERRORS
If an error is detected, getdate() will return NULL and set the error number in getdate_err. The possible error numbers and their meanings are listed below. The DATEMSK environment variable is null or undefined. The template file cannot be opened for reading. Failed to get file status information. The template file is not a regular file. An I/O error occurred while reading the template file. Memory alloca- tion failed (not enough memory available). The template does not have a line that matches the input. Invalid input specification (for example, February 31). A time is specified that cannot be represented in a time_t (representing the time in seconds since 00:00:00 UTC, January 1, 1970). APPLICATION USAGE
Applications should use %Y (4-digit years) instead of %y (2-digit years). RELATED INFORMATION
Functions: ctime(3), ctype(3), setlocale(3), strftime(3) Standards: standards(5) delim off getdate(3)
All times are GMT -4. The time now is 03:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy