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!

3
  • What format do you want to see it in? Commented Oct 25, 2016 at 5:22
  • possible duplicate of 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 might give you an idea. Commented Oct 25, 2016 at 5:31
  • why dont use ng-init to display myTimeFromServer? Commented Oct 25, 2016 at 5:33

2 Answers 2

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());
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! But I need formatted string with time, not date
Please use format 'HH:mm:ss.SSS' to get time upto milliseconds from java date.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.