My application is writen in Spring MVC with the frontend with JQuery datetimepicker. Then i try to format the Date in java, here is what i do :
My main.html page
<body>
<script>
$(function () {
$("#Tgl_Trans").datepicker({ dateFormat: 'yy/mm/dd'});
/* $("#tgl_order").datetimepicker(); */
});
</script>
<div class="form-group" th:classappend="${#fields.hasErrors('Tgl_Trans')} ? error">
<label class="col-sm-2 control-label">Tgl Trans</label>
<div class="col-sm-10">
<div class="col-xs-6">
<input type="text" th:field="*{Tgl_Trans}" class="form-control" required="required" />
<span class="help-inline" th:errors="*{Tgl_Trans}">[error]</span>
</div>
</div>
</div>
</body>
that's the JQuery datetimepicker should be and then here is my object model, which is named orders.java
@Column(name = "Tgl_Trans")
@DateTimeFormat(pattern = "yyyy/MM/dd")
private Date Tgl_Trans;
//the getter setter
public Date getTgl_Trans() {
return Tgl_Trans;
}
public void setTgl_Trans(Date tgl_Trans) {
Tgl_Trans = tgl_Trans;
}
that's where i alreader format the date
and then here is my jdbc class when i trying to insert into my database, which is named JdbcOrdersInsert.java
Date tgl_trans = returorder.getTgl_Trans();
String no_retur = kode_Salesman+ tgl_trans.toString();
what i got is the tgl_trans.toString() become something like this "Sat Feb 28 00:00:00 ICT 2015" that the output how can i format it to be like "20150128"? even can't do tgl_trans.getYear() <-- it give me a strikethrough and warning. what am i missing here?