本文整理汇总了Java中com.ibm.icu.util.GregorianCalendar类的典型用法代码示例。如果您正苦于以下问题:Java GregorianCalendar类的具体用法?Java GregorianCalendar怎么用?Java GregorianCalendar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GregorianCalendar类属于com.ibm.icu.util包,在下文中一共展示了GregorianCalendar类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
}
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:24,代码来源:MCRCalendar.java
示例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;
}
开发者ID:dzxdzx1987,项目名称:GoogleCharts,代码行数:25,代码来源:TimeOfDayValue.java
示例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);
}
}
开发者ID:dzxdzx1987,项目名称:GoogleCharts,代码行数:42,代码来源:DateTimeValue.java
示例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;
}
开发者ID:dzxdzx1987,项目名称:GoogleCharts,代码行数:35,代码来源:DateValue.java
示例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));
}
开发者ID:dzxdzx1987,项目名称:GoogleCharts,代码行数:30,代码来源:DateDiff.java
示例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);
}
开发者ID:eclipse,项目名称:birt,代码行数:20,代码来源:ScriptEvalTest.java
示例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);
}
开发者ID:eclipse,项目名称:birt,代码行数:20,代码来源:ScriptEvalTest.java
示例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 );
}
开发者ID:eclipse,项目名称:birt,代码行数:25,代码来源:DEUtil.java
示例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;
}
开发者ID:anba,项目名称:es6draft,代码行数:18,代码来源:DateTimeFormatObject.java
示例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());
}
}
开发者ID:OpenNTF,项目名称:org.openntf.domino,代码行数:19,代码来源:DateRange.java
示例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;
}
开发者ID:OpenNTF,项目名称:org.openntf.domino,代码行数:26,代码来源:Database.java
示例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];
}
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:35,代码来源:OlsonTimeZone.java
示例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);
}
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:8,代码来源:MCRQueryParser.java
示例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");
}
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:14,代码来源:MCRCalendar.java
示例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;
}
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:37,代码来源:MCRXMLFunctions.java
示例16: getObjectToFormat
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
@Override
public Calendar getObjectToFormat() {
if (isNull()) {
return null;
}
GregorianCalendar cal = new GregorianCalendar(year, month, dayOfMonth);
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
return cal;
}
开发者ID:dzxdzx1987,项目名称:GoogleCharts,代码行数:10,代码来源:DateValue.java
示例17: test_NOT_BETWEEN
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
/**
* @throws DataException
*/
@Test
public void test_NOT_BETWEEN( ) throws DataException
{
Object result;
result = ScriptEvalUtil.evalConditionalExpr(
new Date( ( new GregorianCalendar( 2004, 1, 2 ) ).getTimeInMillis( ) ),
IConditionalExpression.OP_NOT_BETWEEN,
new Timestamp( ( new GregorianCalendar( 2004, 1, 1 ) ).getTimeInMillis( ) ),
new Timestamp( ( new GregorianCalendar( 2004, 1, 3 ) ).getTimeInMillis( ) ) );
assertResult( result, false );
result = ScriptEvalUtil.evalConditionalExpr(
new Date( ( new GregorianCalendar( 2004, 1, 2 ) ).getTimeInMillis( ) ),
IConditionalExpression.OP_NOT_BETWEEN,
new Timestamp( ( new GregorianCalendar( 2004, 1, 3 ) ).getTimeInMillis( ) ),
new Timestamp( ( new GregorianCalendar( 2004, 1, 1 ) ).getTimeInMillis( ) ) );
assertResult( result, true );
result = ScriptEvalUtil.evalConditionalExpr(
new Date( ( new GregorianCalendar( 2004, 1, 2 ) ).getTimeInMillis( ) ),
IConditionalExpression.OP_NOT_BETWEEN,
"01/03/2004",
"01/06/2004" );
assertResult( result, true );
result = ScriptEvalUtil.evalConditionalExpr(
new Date( ( new GregorianCalendar( 2004, 1, 2 ) ).getTimeInMillis( ) ),
IConditionalExpression.OP_NOT_BETWEEN,
"01/06/2004",
"01/03/2004" );
assertResult( result, true );
}
开发者ID:eclipse,项目名称:birt,代码行数:36,代码来源:ScriptEvalTest.java
示例18: getResult
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
public TimeMember getResult( TimeMember member )
{
String[] levels = member.getLevelType( );
int[] values = member.getMemberValue( );
Calendar cal = new GregorianCalendar( TimeMemberUtil.getTimeZone( ),
TimeMemberUtil.getDefaultLocale( ) );
cal.clear( );
translateToCal( cal, levels, values );
if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_YEAR ) )
cal.add( Calendar.YEAR, offset );
else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_QUARTER ) )
cal.add( Calendar.MONTH, offset * 3 );
else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_MONTH ) )
cal.add( Calendar.MONTH, offset );
else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_MONTH ) )
cal.add( Calendar.WEEK_OF_MONTH, offset );
else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_WEEK_OF_YEAR ) )
cal.add( Calendar.WEEK_OF_YEAR, offset );
else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_MONTH ) )
cal.add( Calendar.DAY_OF_MONTH, offset );
else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_YEAR ) )
cal.add( Calendar.DAY_OF_YEAR, offset );
else if ( levelName.equals( TimeMember.TIME_LEVEL_TYPE_DAY_OF_WEEK ) )
cal.add( Calendar.DAY_OF_WEEK, offset );
int[] newValues = getValueFromCal( cal, levels );
TimeMember newMember = new TimeMember( newValues, levels );
return newMember;
}
开发者ID:eclipse,项目名称:birt,代码行数:33,代码来源:PreviousNPeriodsFunction.java
示例19: get
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
@Override
public Calendar get() {
if (super.get() == null) {
set(GregorianCalendar.getInstance());
}
return super.get();
}
开发者ID:OpenNTF,项目名称:org.openntf.domino,代码行数:8,代码来源:DateTime.java
示例20: toJavaCal
import com.ibm.icu.util.GregorianCalendar; //导入依赖的package包/类
@Override
public Calendar toJavaCal() {
if (date_ != null) {
Calendar result = GregorianCalendar.getInstance();
result.setTime(date_);
return result;
} else {
return null;
}
}
开发者ID:OpenNTF,项目名称:org.openntf.domino,代码行数:11,代码来源:DateTime.java
注:本文中的com.ibm.icu.util.GregorianCalendar类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论