Java xmlgregoriancalendar without timezone

Java xmlgregoriancalendar without timezone

Compare two instances of W3C XML Schema 1.0 date/time datatypes according to partial order relation defined in W3C XML Schema 1.0 Part 2, Section 3.2.7.3, Order relation on dateTime.

Return timezone offset in minutes or DatatypeConstants.FIELD_UNDEFINED if this optional field is not defined.

Return low order component for XML Schema 1.0 dateTime datatype field for year or DatatypeConstants.FIELD_UNDEFINED .

Methods inherited from class java.lang.Object

Constructor Detail

XMLGregorianCalendar

public XMLGregorianCalendar()

Default no-arg constructor. Note: Always use the DatatypeFactory to construct an instance of XMLGregorianCalendar . The constructor on this class cannot be guaranteed to produce an object with a consistent state and may be removed in the future.

Method Detail

clear

public abstract void clear()

Unset all fields to undefined. Set all int fields to DatatypeConstants.FIELD_UNDEFINED and reference fields to null.

reset

public abstract void reset()

setYear

Set low and high order component of XSD dateTime year field. Unset this field by invoking the setter with a parameter value of null .

setYear

public abstract void setYear(int year)

Set year of XSD dateTime year field. Unset this field by invoking the setter with a parameter value of DatatypeConstants.FIELD_UNDEFINED . Note: if the absolute value of the year parameter is less than 10^9, the eon component of the XSD year field is set to null by this method.

setMonth

public abstract void setMonth(int month)

Set month. Unset this field by invoking the setter with a parameter value of DatatypeConstants.FIELD_UNDEFINED .

setDay

public abstract void setDay(int day)

Set days in month. Unset this field by invoking the setter with a parameter value of DatatypeConstants.FIELD_UNDEFINED .

setTimezone

public abstract void setTimezone(int offset)

Set the number of minutes in the timezone offset. Unset this field by invoking the setter with a parameter value of DatatypeConstants.FIELD_UNDEFINED .

setTime

public void setTime(int hour, int minute, int second)

setHour

public abstract void setHour(int hour)

Set hours. Unset this field by invoking the setter with a parameter value of DatatypeConstants.FIELD_UNDEFINED .

setMinute

public abstract void setMinute(int minute)

Set minutes. Unset this field by invoking the setter with a parameter value of DatatypeConstants.FIELD_UNDEFINED .

Читайте также:  Добавление пробела в html

setSecond

public abstract void setSecond(int second)

Set seconds. Unset this field by invoking the setter with a parameter value of DatatypeConstants.FIELD_UNDEFINED .

setMillisecond

public abstract void setMillisecond(int millisecond)

Set milliseconds. Unset this field by invoking the setter with a parameter value of DatatypeConstants.FIELD_UNDEFINED .

setFractionalSecond

setTime

setTime

public void setTime(int hour, int minute, int second, int millisecond)

getEon

Return high order component for XML Schema 1.0 dateTime datatype field for year . null if this optional part of the year field is not defined. Value constraints for this value are summarized in year field of date/time field mapping table.

getYear

public abstract int getYear()

Return low order component for XML Schema 1.0 dateTime datatype field for year or DatatypeConstants.FIELD_UNDEFINED . Value constraints for this value are summarized in year field of date/time field mapping table.

getEonAndYear

Return XML Schema 1.0 dateTime datatype field for year . Value constraints for this value are summarized in year field of date/time field mapping table.

getMonth

public abstract int getMonth()

Return number of month or DatatypeConstants.FIELD_UNDEFINED . Value constraints for this value are summarized in month field of date/time field mapping table.

getDay

public abstract int getDay()

Return day in month or DatatypeConstants.FIELD_UNDEFINED . Value constraints for this value are summarized in day field of date/time field mapping table.

getTimezone

public abstract int getTimezone()

Return timezone offset in minutes or DatatypeConstants.FIELD_UNDEFINED if this optional field is not defined. Value constraints for this value are summarized in timezone field of date/time field mapping table.

getHour

public abstract int getHour()

Return hours or DatatypeConstants.FIELD_UNDEFINED . Returns DatatypeConstants.FIELD_UNDEFINED if this field is not defined. Value constraints for this value are summarized in hour field of date/time field mapping table.

getMinute

public abstract int getMinute()

Return minutes or DatatypeConstants.FIELD_UNDEFINED . Returns DatatypeConstants.FIELD_UNDEFINED if this field is not defined. Value constraints for this value are summarized in minute field of date/time field mapping table.

getSecond

public abstract int getSecond()

Return seconds or DatatypeConstants.FIELD_UNDEFINED . Returns DatatypeConstants.FIELD_UNDEFINED if this field is not defined. When this field is not defined, the optional xs:dateTime fractional seconds field, represented by getFractionalSecond() and getMillisecond() , must not be defined. Value constraints for this value are summarized in second field of date/time field mapping table.

getMillisecond

public int getMillisecond()

Return millisecond precision of getFractionalSecond() . This method represents a convenience accessor to infinite precision fractional second value returned by getFractionalSecond() . The returned value is the rounded down to milliseconds value of getFractionalSecond() . When getFractionalSecond() returns null , this method must return DatatypeConstants.FIELD_UNDEFINED . Value constraints for this value are summarized in second field of date/time field mapping table.

Читайте также:  Python tkinter canvas rgb

getFractionalSecond

Return fractional seconds. null is returned when this optional field is not defined. Value constraints are detailed in second field of date/time field mapping table. This optional field can only have a defined value when the xs:dateTime second field, represented by getSecond() , does not return DatatypeConstants.FIELD_UNDEFINED .

compare

Compare two instances of W3C XML Schema 1.0 date/time datatypes according to partial order relation defined in W3C XML Schema 1.0 Part 2, Section 3.2.7.3, Order relation on dateTime. xsd:dateTime datatype field mapping to accessors of this class are defined in date/time field mapping table.

normalize

Normalize this instance to UTC. 2000-03-04T23:00:00+03:00 normalizes to 2000-03-04T20:00:00Z Implements W3C XML Schema Part 2, Section 3.2.7.3 (A).

equals

Compares this calendar to the specified object. The result is true if and only if the argument is not null and is an XMLGregorianCalendar object that represents the same instant in time as this object.

hashCode

toXMLFormat

Return the lexical representation of this instance. The format is specified in XML Schema 1.0 Part 2, Section 3.2.12.1, Lexical Representation«. Specific target lexical representation format is determined by getXMLSchemaType() .

getXMLSchemaType

Return the name of the XML Schema date/time type that this instance maps to. Type is computed based on fields that are set.

Required fields for XML Schema 1.0 Date/Time Datatypes.
(timezone is optional for all date/time datatypes)
Datatype year month day hour minute second
DatatypeConstants.DATETIME X X X X X X
DatatypeConstants.DATE X X X
DatatypeConstants.TIME X X X
DatatypeConstants.GYEARMONTH X X
DatatypeConstants.GMONTHDAY X X
DatatypeConstants.GYEAR X
DatatypeConstants.GMONTH X
DatatypeConstants.GDAY X

toString

Returns a String representation of this XMLGregorianCalendar Object . The result is a lexical representation generated by toXMLFormat() .

isValid

public abstract boolean isValid()

add

Add duration to this instance. The computation is specified in XML Schema 1.0 Part 2, Appendix E, Adding durations to dateTimes>. date/time field mapping table defines the mapping from XML Schema 1.0 dateTime fields to this class’ representation of those fields.

toGregorianCalendar

  • Using timeZone value as defined above, create a new java.util.GregorianCalendar(timeZone,Locale.getDefault()) .
  • Initialize all GregorianCalendar fields by calling Calendar.clear() .
  • Obtain a pure Gregorian Calendar by invoking GregorianCalendar.setGregorianChange( new Date(Long.MIN_VALUE)) .
  • Its fields ERA, YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE, SECOND and MILLISECOND are set using the method Calendar.set(int,int)
Читайте также:  Substring count in php

toGregorianCalendar

public abstract GregorianCalendar toGregorianCalendar(TimeZone timezone, Locale aLocale, XMLGregorianCalendar defaults)
  • when parameter timeZone is non-null, it is the timezone field.
  • else when this.getTimezone() != FIELD_UNDEFINED , create a java.util.TimeZone with a custom timezone id using the this.getTimezone() .
  • else when defaults.getTimezone() != FIELD_UNDEFINED , create a java.util.TimeZone with a custom timezone id using defaults.getTimezone() .
  • else use the GregorianCalendar default timezone value for the host is defined as specified by java.util.TimeZone.getDefault() .
  • Create a new java.util.GregorianCalendar(TimeZone, Locale) with TimeZone set as specified above and the Locale parameter.
  • Initialize all GregorianCalendar fields by calling Calendar.clear()
  • Obtain a pure Gregorian Calendar by invoking GregorianCalendar.setGregorianChange( new Date(Long.MIN_VALUE)) .
  • Its fields ERA, YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE, SECOND and MILLISECOND are set using the method Calendar.set(int,int)

getTimeZone

public abstract TimeZone getTimeZone(int defaultZoneoffset)

Returns a java.util.TimeZone for this class. If timezone field is defined for this instance, returns TimeZone initialized with custom timezone id of zoneoffset. If timezone field is undefined, try the defaultZoneoffset that was passed in. If defaultZoneoffset is FIELD_UNDEFINED, return default timezone for this host. (Same default as java.util.GregorianCalendar).

clone

Источник

Code Destine

If you had worked on a project which consume or publish web services, then you would have faced a problem with date (XMLGregorianCalendar) object, where you would like to send only date string as yyyy-MM-dd but complete yyyy-MM-dd’T’HH:mm:ss’Z’ has been sent. This date string contains date, time and timezone information, if you like to send only date string as yyyy-MM-dd then you have to remove time and timezone information from date object. Let’s see how to remove these information :-

To remove time zone or “Z” from date string, call following method :-

xmlDate.setTimezone( DatatypeConstants.FIELD_UNDEFINED ) 

To remove time information from date string, call following method :-

xmlDate.setTimezone( DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED ) 

Example :-

import java.util.Date; import java.util.GregorianCalendar; import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; public class Main < public static void main(String[] args) < XMLGregorianCalendar xmlDate = null; GregorianCalendar gc = new GregorianCalendar(); gc.setTime(new Date()); try < xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); System.out.println("Complete Date :- " + xmlDate.toString()); // To remove Timezone or "Z" xmlDate.setTimezone(DatatypeConstants.FIELD_UNDEFINED); System.out.println("Without Time Zone :- " + xmlDate.toString()); // To remove Time information xmlDate.setTime(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED); System.out.println("Without Time Zone &amp; Time :- " + xmlDate.toString()); >catch (Exception e) < e.printStackTrace(); >> >

Result :-

Removing Timezone from XMLGregorianCalendar

That’s all for this post, If you liked it, please share your thoughts in comments section and share it with others too.

Источник

Оцените статью