1

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?

Thanks.

2
  • 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
    Commented Feb 13, 2015 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
    Commented Feb 13, 2015 at 18:28

1 Answer 1

4

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .