本文整理汇总了Java中net.fortuna.ical4j.model.DateTime.setTimeZone方法的典型用法代码示例。如果您正苦于以下问题:Java DateTime.setTimeZone方法的具体用法?Java DateTime.setTimeZone怎么用?Java DateTime.setTimeZone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.fortuna.ical4j.model.DateTime
的用法示例。
在下文中一共展示了DateTime.setTimeZone方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: normalizeUTCDateTimeToDate
import net.fortuna.ical4j.model.DateTime; //导入方法依赖的package包/类
/**
* Return a Date instance that represents the day that a point in
* time translates into local time given a timezone.
* @param utcDateTime point in time
* @param tz timezone The timezone.
* @return The date.
*/
public static Date normalizeUTCDateTimeToDate(DateTime utcDateTime, TimeZone tz) {
if(!utcDateTime.isUtc()) {
throw new IllegalArgumentException("datetime must be utc");
}
// if no timezone, use default
if (tz == null) {
return new Date(utcDateTime);
}
DateTime copy = (DateTime) Dates.getInstance(utcDateTime, utcDateTime);
copy.setTimeZone(tz);
try {
return new Date(copy.toString().substring(0, 8));
} catch (ParseException e) {
throw new CosmoParseException("error creating Date instance", e);
}
}
示例2: 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);
}
}
示例3: getInstance
import net.fortuna.ical4j.model.DateTime; //导入方法依赖的package包/类
/**
* Returns a new date instance matching the type and timezone of the other
* date. If no type is specified a DateTime instance is returned.
*
* @param date
* a seed Java date instance
* @param type
* the type of date instance
* @return an instance of <code>net.fortuna.ical4j.model.Date</code>
*/
public static Date getInstance(final java.util.Date date, final Date type) {
if (type instanceof DateTime) {
DateTime dt = new DateTime(date);
if (((DateTime) type).isUtc()) {
dt.setUtc(true);
} else {
dt.setTimeZone(((DateTime) type).getTimeZone());
}
return dt;
} else {
return new Date(date);
}
}
示例4: makeWelcomeItem
import net.fortuna.ical4j.model.DateTime; //导入方法依赖的package包/类
private NoteItem makeWelcomeItem(OutOfTheBoxContext context) {
NoteItem item = entityFactory.createNote();
TimeZone tz= context.getTimezone();
Locale locale = context.getLocale();
User user = context.getUser();
String name = "Welcome to Chandler Server";
String body = "1. Get a tour of Chandler @ chandlerproject.org/getstarted\n\n2. Consult our FAQ @ chandlerproject.org/faq\n\n3. Read about any known issues with the Preview release @ chandlerproject.org/knownissues\n\n4. Ask questions and give us feedback by joining the Chandler-Users mailing list @ chandlerproject.org/mailinglists. Find out how to get involved @ chandlerproject.org/getinvolved\n\n5. Learn more about the project and access a wide range of design, planning and developer documentation @ chandlerproject.org/wikihome";
String from = "OSAF";
String sentBy = "OSAF";
String to = "";
item.setUid(contentDao.generateUid());
item.setDisplayName(name);
item.setOwner(user);
item.setClientCreationDate(Calendar.getInstance(tz, locale).getTime());
item.setClientModifiedDate(item.getClientCreationDate());
TriageStatus triage = entityFactory.createTriageStatus();
TriageStatusUtil.initialize(triage);
item.setTriageStatus(triage);
item.setLastModifiedBy(user.getUsername());
item.setLastModification(ContentItem.Action.CREATED);
item.setSent(Boolean.FALSE);
item.setNeedsReply(Boolean.FALSE);
item.setIcalUid(item.getUid());
item.setBody(body);
Calendar start = Calendar.getInstance(tz, locale);
start.set(Calendar.MINUTE, 0);
start.set(Calendar.SECOND, 0);
DateTime startDate = (DateTime)
Dates.getInstance(start.getTime(), Value.DATE_TIME);
startDate.setTimeZone(vtz(tz.getID()));
EventStamp es = entityFactory.createEventStamp(item);
item.addStamp(es);
es.createCalendar();
es.setStartDate(startDate);
es.setDuration(new Dur(0, 1, 0, 0));
TaskStamp ts = entityFactory.createTaskStamp();
item.addStamp(ts);
MessageStamp ms = entityFactory.createMessageStamp();
item.addStamp(ms);
ms.setFrom(from);
ms.setTo(to);
ms.setOriginators(sentBy);
ms.setDateSent(DateUtil.formatDate(MessageStamp.FORMAT_DATE_SENT,
item.getClientCreationDate()));
return item;
}
示例5: makeTryOutItem
import net.fortuna.ical4j.model.DateTime; //导入方法依赖的package包/类
private NoteItem makeTryOutItem(OutOfTheBoxContext context) {
NoteItem item = entityFactory.createNote();
TimeZone tz= context.getTimezone();
Locale locale = context.getLocale();
User user = context.getUser();
String name = "Download Chandler Desktop";
String body = "Learn more @ chandlerproject.org\n\nDownload @ chandlerproject.org/download";
TriageStatus triage = entityFactory.createTriageStatus();
TriageStatusUtil.initialize(triage);
triage.setCode(TriageStatus.CODE_LATER);
item.setUid(contentDao.generateUid());
item.setDisplayName(name);
item.setOwner(user);
item.setClientCreationDate(Calendar.getInstance(tz, locale).getTime());
item.setClientModifiedDate(item.getClientCreationDate());
item.setTriageStatus(triage);
item.setLastModifiedBy(user.getUsername());
item.setLastModification(ContentItem.Action.CREATED);
item.setSent(Boolean.FALSE);
item.setNeedsReply(Boolean.FALSE);
item.setIcalUid(item.getUid());
item.setBody(body);
Calendar start = Calendar.getInstance(tz, locale);
start.add(Calendar.DAY_OF_MONTH, 1);
start.set(Calendar.HOUR_OF_DAY, 10);
start.set(Calendar.MINUTE, 0);
start.set(Calendar.SECOND, 0);
DateTime startDate = (DateTime)
Dates.getInstance(start.getTime(), Value.DATE_TIME);
startDate.setTimeZone(vtz(tz.getID()));
EventStamp es = entityFactory.createEventStamp(item);
item.addStamp(es);
es.createCalendar();
es.setStartDate(startDate);
es.setDuration(new Dur(0, 1, 0, 0));
TaskStamp ts = entityFactory.createTaskStamp();
item.addStamp(ts);
return item;
}