本文整理汇总了Java中com.ibm.icu.util.GregorianCalendar类的典型用法代码示例。如果您正苦于以下问题:Java GregorianCalendar类的具体用法?Java GregorianCalendar怎么用?Java GregorianCalendar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GregorianCalendar类属于com.ibm.icu.util包,在下文中一共展示了GregorianCalendar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCalendarTypeString
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
/**
* This method returns the calendar type as string.
*
* @param calendar
* the Calendar date
* @return The clendar type as string. If Calendar is empty an empty string will be returned.
*/
public static String getCalendarTypeString(Calendar calendar) {
if (calendar == null) {
return "";
}
if (calendar instanceof IslamicCalendar) {
return TAG_ISLAMIC;
} else if (calendar instanceof CopticCalendar) {
return TAG_COPTIC;
} else if (calendar instanceof EthiopicCalendar) {
return TAG_ETHIOPIC;
} else if (calendar instanceof GregorianCalendar) {
return TAG_GREGORIAN;
} else {
return TAG_JULIAN;
}
}
示例2: getObjectToFormat
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
/**
* A method to retrieve a formattable object for this object.
* It is important to set the GMT TimeZone to avoid conversions related to TimeZone.
*/
@Override
public Calendar getObjectToFormat() {
if (isNull()) {
return null;
}
// Set GMT TimeZone.
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
// Set to some predefined default. Don't change this default.
cal.set(Calendar.YEAR, 1899);
cal.set(Calendar.MONTH, Calendar.DECEMBER);
cal.set(Calendar.DAY_OF_MONTH, 30);
// Set the TimeOfDay based on this TimeOfDayValue.
cal.set(Calendar.HOUR_OF_DAY, hours);
cal.set(Calendar.MINUTE, minutes);
cal.set(Calendar.SECOND, seconds);
cal.set(Calendar.MILLISECOND, milliseconds);
return cal;
}
示例3: DateTimeValue
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
/**
* Creates a new DateTime value.
* The input is checked using a gregorian calendar.
* Note this uses the java convention for months:
* January = 0, ..., December = 11.
*
* @param year The year.
* @param month The month.
* @param dayOfMonth The day of month.
* @param hours The hours.
* @param minutes The minutes.
* @param seconds The seconds.
* @param milliseconds The milliseconds.
*
* @throws IllegalArgumentException Thrown if one of the
* parameters is illegal.
*/
public DateTimeValue(int year, int month, int dayOfMonth, int hours,
int minutes, int seconds, int milliseconds) {
// Constructs a GregorianCalendar with the given date and time.
calendar = new GregorianCalendar(year, month, dayOfMonth, hours,
minutes, seconds);
calendar.set(GregorianCalendar.MILLISECOND, milliseconds);
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
// Check input.
// A RunTimeException is thrown here since it is very unusual for structured
// data to be incorrect.
if ((getYear() != year)
|| (getMonth() != month)
|| (getDayOfMonth() != dayOfMonth)
|| (getHourOfDay() != hours)
|| (getMinute() != minutes)
|| (getSecond() != seconds)
|| (getMillisecond() != milliseconds)) {
throw new IllegalArgumentException("Invalid java date "
+ "(yyyy-MM-dd hh:mm:ss.S): "
+ year + '-' + month + '-' + dayOfMonth + ' ' + hours + ':'
+ minutes + ':' + seconds + '.' + milliseconds);
}
}
示例4: DateValue
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
/**
* Creates a new date value.
* The input is checked using a GregorianCalendar.
* Note that we use java convention for months:
* January = 0, ..., December = 11.
*
* @param year The year.
* @param month The month.
* @param dayOfMonth The day in the month.
*
* @throws IllegalArgumentException Thrown when one of the
* parameters is illegal.
*/
public DateValue(int year, int month, int dayOfMonth) {
// Constructs a GregorianCalendar with the given date set in
// the default time zone.
GregorianCalendar calendar =
new GregorianCalendar(year, month, dayOfMonth);
// Input check. If the date is invalid the calendar object will output
// different fields for year, month and/or dayOfMonth.
// A RunTimeException is thrown here since it is very unusual for structured
// data to be incorrect.
if ((calendar.get(GregorianCalendar.YEAR) != year)
|| (calendar.get(GregorianCalendar.MONTH) != month)
|| (calendar.get(GregorianCalendar.DAY_OF_MONTH) != dayOfMonth)) {
throw new IllegalArgumentException("Invalid java date (yyyy-MM-dd): "
+ year + '-' + month + '-' + dayOfMonth);
}
// Assign internal variables.
this.year = year;
this.month = month;
this.dayOfMonth = dayOfMonth;
}
示例5: evaluate
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
/**
* Executes this scalar function on the given values. Returns values[0] - values[1] expressed
* as a number value denoting the number of days from one date to the other. Both values can be
* of type date or date-time. Only the date parts of date-time values are used in the calculation.
* Thus the returned number is always an integer.
* The method does not validate the parameters, the user must check the
* parameters before calling this method.
*
* @param values A list of values on which the scalar function will be performed.
*
* @return Value holding the difference, in whole days, between the two given Date/DateTime
* values, or a null value (of type number) if one of the values is null.
*/
public Value evaluate(List<Value> values) {
Value firstValue = values.get(0);
Value secondValue = values.get(1);
// If one of the values is null, return a null number value.
if (firstValue.isNull() || secondValue.isNull()) {
return NumberValue.getNullValue();
}
Date firstDate = getDateFromValue(firstValue);
Date secondDate = getDateFromValue(secondValue);
GregorianCalendar calendar =
new GregorianCalendar(TimeZone.getTimeZone("GMT"));
calendar.setTime(secondDate);
return new NumberValue(calendar.fieldDifference(firstDate, Calendar.DATE));
}
示例6: test_GE
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
/**
* @throws DataException
*/
@Test
public void test_GE( ) throws DataException
{
Object result;
result = ScriptEvalUtil.evalConditionalExpr( new BigDecimal(10),
IConditionalExpression.OP_GE, new Double(10.0), null );
assertResult(result,true);
result = ScriptEvalUtil.evalConditionalExpr( new Date((new GregorianCalendar(2004,1,2)).getTimeInMillis()),
IConditionalExpression.OP_GE, new Timestamp((new GregorianCalendar(2004,1,3)).getTimeInMillis()), null );
assertResult(result,false);
result = ScriptEvalUtil.evalConditionalExpr( new Date((new GregorianCalendar(2004,1,2)).getTimeInMillis()),
IConditionalExpression.OP_GE, "01/01/2004", null );
assertResult(result,true);
}
示例7: test_LE
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
/**
* @throws DataException
*/
@Test
public void test_LE( ) throws DataException
{
Object result;
result = ScriptEvalUtil.evalConditionalExpr( new BigDecimal(10),
IConditionalExpression.OP_LE, new Double(10.0), null );
assertResult(result,true);
result = ScriptEvalUtil.evalConditionalExpr( new Date((new GregorianCalendar(2004,1,2)).getTimeInMillis()),
IConditionalExpression.OP_LE, new Timestamp((new GregorianCalendar(2004,1,3)).getTimeInMillis()), null );
assertResult(result,true);
result = ScriptEvalUtil.evalConditionalExpr( new Date((new GregorianCalendar(2004,1,2)).getTimeInMillis()),
IConditionalExpression.OP_LE, "01/01/2004", null );
assertResult(result,false);
}
示例8: convertToXMLString
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
public static String convertToXMLString( Date date )
{
if ( date == null )
{
return null;
}
GregorianCalendar cal = new GregorianCalendar( );
cal.setTime( date );
String pattern = XMLDATE_PATTERN_FULL;
if ( !cal.isSet( Calendar.HOUR ) )
{
pattern = XMLDATE_PATTERN_DATE_ONLY;
}
else if ( !cal.isSet( Calendar.SECOND ) )
{
pattern = XMLDATE_PATTERN_WITH_OUT_SECOND;
}
else if ( !cal.isSet( Calendar.MILLISECOND ) )
{
pattern = XMLDATE_PATTERN_WITH_OUT_MILLISECOND;
}
DateFormatter formater = new DateFormatter( pattern );
return formater.format( date );
}
示例9: createDateFormat
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
private DateFormat createDateFormat() {
ULocale locale = ULocale.forLanguageTag(this.locale);
// calendar and numberingSystem are already handled in language-tag
// assert locale.getKeywordValue("calendar").equals(calendar);
// assert locale.getKeywordValue("numbers").equals(numberingSystem);
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern.get(), locale);
if (timeZone != null) {
dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
}
Calendar calendar = dateFormat.getCalendar();
if (calendar instanceof GregorianCalendar) {
// format uses a proleptic Gregorian calendar with no year 0
GregorianCalendar gregorian = (GregorianCalendar) calendar;
gregorian.setGregorianChange(new Date(Long.MIN_VALUE));
}
return dateFormat;
}
示例10: getDays
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
public List<Date> getDays() {
try {
final List<Date> dates = new ArrayList<Date>();
final Calendar calendar = new GregorianCalendar();
calendar.setTime(this.getStartDate());
while (calendar.getTime().before(this.getEndDate())) {
final Date result = calendar.getTime();
dates.add(result);
calendar.add(Calendar.DATE, 1);
}
return dates;
} catch (final Exception e) {
throw new RuntimeException((null == e.getCause()) ? e : e.getCause());
}
}
示例11: getDailyModifiedNoteCount
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
public int[] getDailyModifiedNoteCount(final java.util.Date since, final Set<SelectOption> noteClass) {
Date now = new Date();
Calendar cal = new GregorianCalendar();
cal.setTime(since);
int diffDays = cal.fieldDifference(now, Calendar.DAY_OF_YEAR);
int[] result = null;
if (diffDays > DAILY_ARRAY_LIMIT) {
result = new int[DAILY_ARRAY_LIMIT];
} else {
result = new int[diffDays];
}
cal.setTime(now);
for (int i = 0; i < result.length; i++) {
if (i == 0) {
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
} else {
cal.add(Calendar.DAY_OF_YEAR, -1);
}
result[i] = getModifiedNoteCount(cal.getTime(), noteClass);
}
return result;
}
示例12: getOffset
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
/**
* TimeZone API.
*/
public int getOffset(int era, int year, int month,int dom, int dow, int millis, int monthLength){
if ((era != GregorianCalendar.AD && era != GregorianCalendar.BC)
|| month < Calendar.JANUARY
|| month > Calendar.DECEMBER
|| dom < 1
|| dom > monthLength
|| dow < Calendar.SUNDAY
|| dow > Calendar.SATURDAY
|| millis < 0
|| millis >= Grego.MILLIS_PER_DAY
|| monthLength < 28
|| monthLength > 31) {
throw new IllegalArgumentException();
}
if (era == GregorianCalendar.BC) {
year = -year;
}
if (finalZone != null && year >= finalStartYear) {
return finalZone.getOffset(era, year, month, dom, dow, millis);
}
// Compute local epoch millis from input fields
long time = Grego.fieldsToDay(year, month, dom) * Grego.MILLIS_PER_DAY + millis;
int[] offsets = new int[2];
getHistoricalOffset(time, true, LOCAL_DST, LOCAL_STD, offsets);
return offsets[0] + offsets[1];
}
示例13: getToday
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
private String getToday() {
GregorianCalendar cal = new GregorianCalendar();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1;
int day = cal.get(Calendar.DAY_OF_MONTH);
return String.valueOf(day) + "." + String.valueOf(month) + "." + String.valueOf(year);
}
示例14: getCalendarDateToFormattedString
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
/**
* This method returns the date as string in format 'yy-MM-dd G'.
*
* @return the date string
*/
public static String getCalendarDateToFormattedString(Calendar calendar) {
if (calendar instanceof IslamicCalendar) {
return getCalendarDateToFormattedString(calendar, "dd.MM.yyyy");
} else if (calendar instanceof GregorianCalendar) {
return getCalendarDateToFormattedString(calendar, "yyyy-MM-dd G");
}
return getCalendarDateToFormattedString(calendar, "yyyy-MM-dd G");
}
示例15: getISODateFromMCRHistoryDate
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
/**
* The method get a date String in format yyyy-MM-ddThh:mm:ssZ for ancient date values.
*
* @param date_value the date string
* @param field_name the name of field of MCRMetaHistoryDate, it should be 'von' or 'bis'
* @param calendar_name the name if the calendar defined in MCRCalendar
* @return the date in format yyyy-MM-ddThh:mm:ssZ
*/
public static String getISODateFromMCRHistoryDate(String date_value, String field_name, String calendar_name)
throws ParseException {
String formatted_date;
if (field_name == null || field_name.trim().length() == 0) {
return "";
}
boolean use_last_value = false;
if ("bis".equals(field_name)) {
use_last_value = true;
}
try {
Calendar calendar = MCRCalendar.getHistoryDateAsCalendar(date_value, use_last_value, calendar_name);
GregorianCalendar g_calendar = MCRCalendar.getGregorianCalendarOfACalendar(calendar);
formatted_date = MCRCalendar.getCalendarDateToFormattedString(g_calendar, "yyyy-MM-dd") + "T00:00:00.000Z";
if (g_calendar.get(GregorianCalendar.ERA) == GregorianCalendar.BC) {
formatted_date = "-" + formatted_date;
}
} catch (Exception e) {
String errorMsg = "Error while converting date string : " + date_value + " - " + use_last_value +
" - " + calendar_name;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(errorMsg, e);
}
LOGGER.warn(errorMsg);
return "";
}
return formatted_date;
}