Re: [Vala] Date format



    > On Wednesday, 28 March 2018, 11:15:48 BST, rastersoft <raster rastersoft com> wrote: >> Pass "%x" for 
the format string.
I used that, but the year is printed with only two digits... Also, what 
I really want is the date in the format "March 5, 2018", not "03/05/18", 
but it seems that only %c does that, but adds a lot of extra data that I 
don't want like the time zone.
As Christian Hergert suggests, DateTime is very useful. This works for me:
void main () {
    var date = new DateTime.now_local();
    print (date.format("%B %e, %Y"));
}
That prints March 28, 2018 today. There are a whole load of formatting options to play around with 
though:https://valadoc.org/glib-2.0/GLib.DateTime.format.html
Regards,
Al
  


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