简体   繁体   中英

Html input type time and Java Date object

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!

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());

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM