0

I have a Java date object. How it should be converted (I mean string presentation) to be displayed as HTML:

<input type='time' ng-model='myTimeFromServer'/>

myTimeFromServer in ng-model is String from server new Date().toString() I need to use input because it is predefined value that user can change.

Thanks in advance!

JodaStephen
  • 60,927
  • 15
  • 95
  • 117
jahra
  • 1,173
  • 1
  • 16
  • 41
  • What format do _you_ want to see it in? – nikjohn Oct 25 '16 at 05:22
  • possible duplicate of [http://stackoverflow.com/questions/5619202/converting-string-to-date-in-js](http://stackoverflow.com/questions/5619202/converting-string-to-date-in-js). Try moment.js than relying on the native JS Date object. The API [here](http://momentjs.com/docs/#/parsing/string-format/) might give you an idea. – Mahesh Oct 25 '16 at 05:31
  • why dont use ``ng-init`` to display ``myTimeFromServer``? – Donald Wu Oct 25 '16 at 05:33

2 Answers2

1

The java date object needs to be formatted to string in the format you want. Below is snippet of code to format date in format 'dd/MM/yyyy' using SimpleDateFormat.

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String formattedDate = sdf.format(new Date());
Rahul M
  • 11
  • 2
0

Java Date's toString only returns the date in yyyy-mm-dd format. So if you need time you should use getTime instead and use Javascript setTime on the other side. Both handles milliseconds.

rics
  • 5,494
  • 5
  • 33
  • 42