My webservice requires an input parameter of datetime of this format : yyyy-mm-dd-hh.mm.ss.fff. I tried this:

Datetime myDT = Datetime.now(); 
String myDate = myDT.format('yyyy-mm-dd-hh.mm.ss.fff');

says the format is not recognized. How do I create a date time in this format?


  • 1
    Shouldn't the format be yyyy-MM-dd-hh.mm.ss.SSS? Capital M is for month and lower case is for minute. Also capital S is for milliseconds. The letters are listed here – BarCotter Feb 13 '15 at 18:25
  • 1
    hh will display the hours in 12 hour format and HH will display it in 24 hour format. HH might be what you are looking to use if you are using this format to create a unique string. – BarCotter Feb 13 '15 at 18:28

Your format template does not match the valid strings.

As BarCotter said, yyyy-MM-dd-hh.mm.ss.SSS will work since it uses the formatting as described here: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.