Re: [Vala] Date format




http://linux.about.com/library/cmd/blcmdl3_nl_langinfo.htm

you should be able to pull the formats using the above --

reid
On Tue, 2011-10-25 at 22:06 +0200, rastersoft wrote:
Thanks, but that doesn't solve my problem. I already got access to that, 
and tested format("%x"); unfortunately, it puts the year as a two-digit 
number.

I want the same than format("%x") but with four-digit years; the problem 
is how to know if the current locale mandates to write month/day/year or 
day/month/year.

Currently I do a check at program startup, doing format("%x") for date 
day 1, month 3, year 2005, and check the output: if there's a 3 as the 
first number, then the order is month/day/year; if not, it's 
day/month/year. Unfortunately, that's an extremely ugly hack. So I want 
to know if is there a straightforward way of doing this.

Thanks.

El 25/10/11 15:35, Reid Thompson escribió:
On Mon, 2011-10-24 at 22:33 +0200, rastersoft wrote:
I want to print a date in the format dd/mm/yyyy or mm/dd/yyyy,
acording
slightly modified from http://live.gnome.org/Vala/TimeSample

void main () {

     // A DateTime from a Unix timestamp
     int64 timestamp = 1234151912;
     var time = new DateTime.from_unix_utc (timestamp);
     // convert back to Unix timestamp
     assert (time.to_unix () == timestamp);

     // A DateTime from year, month, day, hour, minute, second
     time = new DateTime.utc (2010, 10, 22, 9, 22, 0);

     // The current time in local timezone
     var now = new DateTime.now_local ();
     print ("Is daylight savings time: %s\n", now.is_daylight_savings () ? "yes" : "no");
     print ("The timezone abbreviation is: %s\n", now.get_timezone_abbreviation ());

     // returns time in RFC 3339 format: 2010-10-21T23:48:03+0200
     string date_string = now.to_string ();
     print ("Current time in RFC 3339 format: %s\n", date_string);

     // for example, according to the current locale
     print ("According to the current locale: %s\n", now.format ("%x %X"));

     print ("Day of month: %d\n", now.get_day_of_month ());
     print ("Week of year: %d\n", now.get_week_of_year ());

     // Add one day, three hours and five minutes to a DateTime:
     var future = now.add_days (1).add_hours (3).add_minutes (5);
     print (@"Plus one day, three hours and five minutes: $future\n");


     print ("According to the current locale: %s\n", now.format ("%d/%m/%Y"));
     print ("According to the current locale: %s\n", now.format ("%m/%d/%Y"));

}








[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]