java - Format XMLGregorianCalendar -


below code

gregoriancalendar gregory=new gregoriancalendar(); gregory.settime(new date()); xmlgregoriancalendar xmlgregoriancalendar=datatypefactory.newinstance().newxmlgregoriancalendar(gregory); system.out.println(xmlgregoriancalendar.tostring()); 

when printing sop in last line of above code getting output

2016-07-28t15:25:47.064+05:30 

but iam trying output

2016-07-28+05:30 

i have tried different formatters no luck.

any suggestions helpfull me

atleast can format using simpledateformat?

by using simpledateformat iam able "2016-07-29+0530". can please let me know if can bring ":" in between "05" , "30". code below

dateformat dateformat = new simpledateformat("yyyy-mm-ddz"); 

in java version 7 , 8 possible using below

dateformat dateformat = new simpledateformat("yyyy-mm-ddxxx"); 

but not sure in java 6 version

the easiest rebuild jdk7 functionality. have know new xxx calculation based on available fields of calendar class. take calendar.zone_offset , calendar.dst_offset , go there this:

    int totaloffset = calendar.get(calendar.zone_offset) + calendar.get(calendar.dst_offset);      stringbuilder sb = new stringbuilder();      //handle 0 offset     if (totaloffset == 0) {         sb.append('z');     }      //convert minutes because timezones minute based     totaloffset = totaloffset / 60000;     char prefix = '-';     if (totaloffset >= 0) {         prefix = '+';     }     sb.append(prefix);      //if negative offset, invert     totaloffset = math.abs(totaloffset);      sb.append(string.format("%02d", (totaloffset / 60)));     sb.append(':');     sb.append(string.format("%02d", (totaloffset % 60)));      system.out.println(sb.tostring()); 

i hope snippet helps go there.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -