How to format DateTime to 24 hours time?
Use upper-case HH for 24h format: String s = curr.ToString(“HH:mm”); See DateTime.ToString Method.
Use upper-case HH for 24h format: String s = curr.ToString(“HH:mm”); See DateTime.ToString Method.
This warning is gcc’s way of telling you that it cannot verify the format string argument to the printf style function (printf, fprintf… etc). This warning is generated when the compiler can’t manually peek into the string and ensure that everything will go as you intend during runtime. Lets look at a couple of examples. … Read more
You can use advanced string formatting, available in Python 2.6 and Python 3.x: incoming = ‘arbit’ result=”{0} hello world {0} hello world {0}”.format(incoming)
There is a possibility with printf, it goes like this: printf(“%.*s”, stringLength, pointerToString); No need to copy anything, no need to modify the original string or buffer.
This is one of the functions of getimagesize. They probably should have called it “getimageinfo”, but that’s PHP for you.
What you’re basically doing here is relying on Date#toString() which already has a fixed pattern. To convert a Java Date object into another human readable String pattern, you need SimpleDateFormat#format(). private String modifyDateLayout(String inputDate) throws ParseException{ Date date = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss z”).parse(inputDate); return new SimpleDateFormat(“dd.MM.yyyy HH:mm:ss”).format(date); } By the way, the “unparseable date” exception … Read more
As @TimPietzcker suggested, the dateutil package is the way to go, it handles the first 3 formats correctly and automatically: >>> from dateutil.parser import parse >>> parse(“Fri Sep 25 18:09:49 -0500 2009”) datetime.datetime(2009, 9, 25, 18, 9, 49, tzinfo=tzoffset(None, -18000)) >>> parse(“2008-06-29T00:42:18.000Z”) datetime.datetime(2008, 6, 29, 0, 42, 18, tzinfo=tzutc()) >>> parse(“2011-07-16T21:46:39Z”) datetime.datetime(2011, 7, 16, 21, … Read more
You cant! If you have the date 2010-08-05 then it can be either 5th August 2010, or 8th May 2010 – you need to know the date format (or at least prioritise one format over the over) to tell them apart.
Try each format and see if it works: from datetime import datetime def try_parsing_date(text): for fmt in (‘%Y-%m-%d’, ‘%d.%m.%Y’, ‘%d/%m/%Y’): try: return datetime.strptime(text, fmt) except ValueError: pass raise ValueError(‘no valid date format found’)
public class LeadingZerosExample { public static void main(String[] args) { int number = 1500; // String format below will add leading zeros (the %0 syntax) // to the number above. // The length of the formatted string will be 7 characters. String formatted = String.format(“%07d”, number); System.out.println(“Number with leading zeros: ” + formatted); } }