how to convert XMLGregorian Calendar to java.util.Date in GMT(Greenwich) time -
i trying convert xmlgregorian calendar java.util.date in gmt.but following method gives me same date.it not convert date. can please @ below code , tell me doing wrong ?
try { simpledateformat dateformatgmt = new simpledateformat("yyyy-mmm-dd hh:mm"); dateformatgmt.settimezone(timezone.gettimezone("utc")); return dateformatgmt.parse(dateformatgmt.format(date)); } catch (parseexception e) { e.printstacktrace(); return null; }
java.time
avoid troublesome old date-time classes, supplanted java.time classes.
convert xmlgregoriancalendar
object java.util.gregoriancalendar
. there java.time.zoneddatetime
. there java.time.instant
in utc (the new gmt, basically).
gregoriancalendar gc = myxgc.togregoriancalendar() ; zoneddatetime zdt = gc.tozoneddatetime() ; instant instant = zdt.toinstant() ;
if absolutely must have java.util.date
, convert using new methods added old classes.
java.util.date d = date.from( instant ) ;
search stack overflow more info. question duplicate of many others.
Comments
Post a Comment