当前位置: 首页>>代码示例>>Java>>正文


Java DateTime.toString方法代码示例

本文整理汇总了Java中net.fortuna.ical4j.model.DateTime.toString方法的典型用法代码示例。如果您正苦于以下问题:Java DateTime.toString方法的具体用法?Java DateTime.toString怎么用?Java DateTime.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.fortuna.ical4j.model.DateTime的用法示例。


在下文中一共展示了DateTime.toString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: normalizeUTCDateTimeToDefaultOffset

import net.fortuna.ical4j.model.DateTime; //导入方法依赖的package包/类
/**
 * Return a DateTime instance that is normalized according to the
 * offset of the specified timezone as compared to the default
 * system timezone.
 * 
 * @param utcDateTime point in time
 * @param tz timezone The timezone.
 * @return The date.
 */
public static Date normalizeUTCDateTimeToDefaultOffset(DateTime utcDateTime, TimeZone tz) {
    if(!utcDateTime.isUtc()) {
        throw new IllegalArgumentException("datetime must be utc");
    }
    
    // if no timezone nothing to do
    if (tz == null) {
        return utcDateTime;
    }
    
    // create copy, and set timezone
    DateTime copy = (DateTime) Dates.getInstance(utcDateTime, utcDateTime);
    copy.setTimeZone(tz);
    
    
    // Create floating instance of local time, which will give
    // us the correct offset
    try {
        return new DateTime(copy.toString());
    } catch (ParseException e) {
        throw new CosmoParseException("error creating Date instance", e);
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:33,代码来源:ICalendarUtils.java

示例2: fromDateToStringNoTimezone

import net.fortuna.ical4j.model.DateTime; //导入方法依赖的package包/类
private String fromDateToStringNoTimezone(Date date) {
    if(date==null) {
        return null;
    }
    
    if(date instanceof DateTime) {
        DateTime dt = (DateTime) date;
        // If DateTime has a timezone, then convert to UTC before
        // serializing as String.
        if(dt.getTimeZone()!=null) {
            // clone instance first to prevent changes to original instance
            DateTime copy = new DateTime(dt);
            copy.setUtc(true);
            return copy.toString();
        } else {
            return dt.toString();
        }
    } else {
        return date.toString();
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:22,代码来源:EventStampInterceptor.java

示例3: fromDateToStringNoTimezone

import net.fortuna.ical4j.model.DateTime; //导入方法依赖的package包/类
/**
 * Converts an ical4j Date instance to a string representation.  If the instance
 * is a DateTime and has a timezone, then the string representation will be
 * UTC.
 * @param date date to format
 * @return string representation of date
 */
public static String fromDateToStringNoTimezone(Date date) {
    if(date==null) {
        return null;
    }
    
    if(date instanceof DateTime) {
        DateTime dt = (DateTime) date;
        // If DateTime has a timezone, then convert to UTC before
        // serializing as String.
        if(dt.getTimeZone()!=null) {
            // clone instance first to prevent changes to original instance
            DateTime copy = new DateTime(dt);
            copy.setUtc(true);
            return copy.toString();
        } else {
            return dt.toString();
        }
    } else {
        return date.toString();
    }
}
 
开发者ID:1and1,项目名称:cosmo,代码行数:29,代码来源:ModificationUidImpl.java

示例4: adjustFloatingDateIfNecessary

import net.fortuna.ical4j.model.DateTime; //导入方法依赖的package包/类
/**
 * Adjust a floating time if a timezone is present.  A floating time
 * is initially created with the default system timezone.  If a timezone
 * if present, we need to adjust the floating time to be in specified
 * timezone.  This allows a server in the US to return floating times for
 * a query made by someone whos timezone is in Australia.  If no timezone is
 * set for the InstanceList, then the system default timezone will be
 * used in floating time calculations.
 * <p/>
 * What happens is a floating time will get converted into a
 * date/time with a timezone.  This is ok for comparison and recurrence
 * generation purposes.  Note that Instances will get indexed as a UTC
 * date/time and for floating DateTimes, the the recurrenceId associated
 * with the Instance loses its "floating" property.
 *
 * @param date The date.
 * @return The date.
 */
private Date adjustFloatingDateIfNecessary(Date date) {
    if (timezone == null || !(date instanceof DateTime)) {
        return date;
    }

    DateTime dtDate = (DateTime) date;
    if (dtDate.isUtc() || dtDate.getTimeZone() != null) {
        return date;
    }

    try {
        return new DateTime(dtDate.toString(), timezone);
    } catch (ParseException e) {
        throw new CosmoParseException("error parsing date", e);
    }
}
 
开发者ID:ksokol,项目名称:carldav,代码行数:35,代码来源:InstanceList.java


注:本文中的net.fortuna.ical4j.model.DateTime.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。