本文整理匯總了Java中org.ocpsoft.prettytime.PrettyTime.format方法的典型用法代碼示例。如果您正苦於以下問題:Java PrettyTime.format方法的具體用法?Java PrettyTime.format怎麽用?Java PrettyTime.format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.ocpsoft.prettytime.PrettyTime
的用法示例。
在下文中一共展示了PrettyTime.format方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCommand
import org.ocpsoft.prettytime.PrettyTime; //導入方法依賴的package包/類
/**
* Check when the specified person last spoke and return with a response.
*/
@Override
public void onCommand(CommandEvent commandEvent) {
if (commandEvent.getArgs().length == 0) {
return;
}
// Preparing and responding using query
String nick = Joiner.on(" ").join(commandEvent.getArgs());
try {
PreparedStatement statement = TitanBot.getDatabaseConnection().prepareStatement(
"SELECT seen FROM seen WHERE nick LIKE ?"
);
statement.setString(1, nick);
ResultSet resultSet = statement.executeQuery();
PrettyTime prettyTime = new PrettyTime();
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(resultSet.getString("seen"));
String pretty = prettyTime.format(date);
TitanBot.sendReply(commandEvent.getSource(), "I last saw " + nick + " " + pretty + ".");
} catch(Exception e) {
TitanBot.sendReply(commandEvent.getSource(), "I have never seen " + nick + ".");
}
}
示例2: exec
import org.ocpsoft.prettytime.PrettyTime; //導入方法依賴的package包/類
@Override
public Object exec(List arguments) throws TemplateModelException {
if (arguments.size() < 1) {
throw new TemplateModelException("require an Instant as argument");
}
if (arguments.size() > 2) {
throw new TemplateModelException("too many arguments");
}
PrettyTime prettyTime = new PrettyTime(Environment.getCurrentEnvironment().getLocale());
// only support day unit now
if (arguments.size() == 2 && arguments.get(1).toString().equals("Day")) {
List<TimeUnit> units = prettyTime.getUnits()
.stream()
.filter(timeUnit -> timeUnit.getMillisPerUnit() > new Day().getMillisPerUnit())
.collect(Collectors.toList());
units.forEach(prettyTime::removeUnit);
}
StringModel stringModel = (StringModel) arguments.get(0);
Instant instant = (Instant) stringModel.getAdaptedObject(Instant.class);
return prettyTime.format(Date.from(instant));
}
示例3: getPrettyTimeLeft
import org.ocpsoft.prettytime.PrettyTime; //導入方法依賴的package包/類
@JsonIgnore
public String getPrettyTimeLeft() {
PrettyTime p = new PrettyTime();
p.setLocale(Locale.ENGLISH);
if (currentTurn.getExpires() != null) {
return "Expires: " + p.format(currentTurn.getExpires().toDate());
} else {
return "Last turn: " + p.format(currentTurn.getStarted().toDate());
}
}
示例4: toString
import org.ocpsoft.prettytime.PrettyTime; //導入方法依賴的package包/類
@Override
public String toString() {
PrettyTime p = new PrettyTime();
p.setLocale(Locale.ENGLISH);
if (currentTurn.getExpires() != null) {
return this.name + " || Expires: " + p.format(currentTurn.getExpires().toDate());
} else {
return this.name + " || Last turn: " + p.format(currentTurn.getStarted().toDate());
}
}
示例5: getNextEpDate
import org.ocpsoft.prettytime.PrettyTime; //導入方法依賴的package包/類
/**
* Formats the epotch time to a pretty data
* <br/>
* @return string such as "EP 6 Airing in 2 hours"
* @param airing - the current airing object of a series
*/
public static String getNextEpDate(Airing airing){
if(airing == null)
return "N/A";
else {
PrettyTime prettyTime = new PrettyTime(Locale.getDefault());
String from_now = prettyTime.format(new Date(System.currentTimeMillis()+(airing.getCountdown()*1000L)));
return String.format(Locale.getDefault(), "EP %d - %s",airing.getNext_episode(), from_now);
}
}
示例6: getPrettyDate
import org.ocpsoft.prettytime.PrettyTime; //導入方法依賴的package包/類
/**
* Generates a pretty data "x y from now" where y can be minutes, hours, days or even weeks e.t.c
* <br/>
* @return Pretty Date (x hours from now / x hours ago)
* @param date - a date with the format of yyyy-MM-dd HH:mm:ss
*/
public static String getPrettyDate(String date) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.getDefault());
try {
Date converted = format.parse(date);
PrettyTime prettyTime = new PrettyTime(Locale.getDefault());
return prettyTime.format(converted);
} catch (ParseException e) {
e.printStackTrace();
}
return "Unknown Time";
}
示例7: getPrettyDateCustom
import org.ocpsoft.prettytime.PrettyTime; //導入方法依賴的package包/類
/**
* For dates that don't include a timezones,
* the underlying method sets the time with a +7 offset
* <br/>
* @param date - a date with the format of yyyy-MM-dd HH:mm:ss
*/
public static String getPrettyDateCustom(String date) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.getDefault());
format.setTimeZone(TimeZone.getTimeZone("Japan"));
try {
Date converted = format.parse(date);
PrettyTime prettyTime = new PrettyTime(Locale.getDefault());
return prettyTime.format(converted);
} catch (ParseException e) {
e.printStackTrace();
}
return "Unknown Time";
}
示例8: createUptimeModel
import org.ocpsoft.prettytime.PrettyTime; //導入方法依賴的package包/類
private IModel<String> createUptimeModel() {
return new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
SystemInfoDto dto = getModelObject();
PrettyTime time = new PrettyTime();
return time.format(new Date(System.currentTimeMillis() - dto.uptime));
}
};
}
示例9: getMoment
import org.ocpsoft.prettytime.PrettyTime; //導入方法依賴的package包/類
public String getMoment() throws ParseException {
PrettyTime p = new PrettyTime();
//http://www.datameer.com/documentation/display/DAS20/Date+and+Time+Parse+Patterns
String ISO_FORMAT1 = "yyyy-MM-dd'T'HH:mm:ss.SSS zzz";
String ISO_FORMAT2 = "yyyy-MM-dd'T'HH:mm:ss.SSS";
String ISO_FORMAT3 = "yyyy-MM-dd HH:mm:ss z";
String ISO_FORMAT4 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
String ISO_FORMAT5 = "yyyy-MM-dd'T'HH:mm:ssZ";
Date parsedTimeStamp = new SimpleDateFormat(ISO_FORMAT5, new Locale("en", "US")).parse(getDate());
return p.format(parsedTimeStamp);
}
示例10: getFormattedImportDate
import org.ocpsoft.prettytime.PrettyTime; //導入方法依賴的package包/類
@Transactional
public String getFormattedImportDate() {
PrettyTime p = new PrettyTime(new Locale("en"));
Date d = extractHistoryDao.getLastExtractDate();
return p.format(d);
}
示例11: getLastLoginString
import org.ocpsoft.prettytime.PrettyTime; //導入方法依賴的package包/類
public String getLastLoginString() {
if (isAnonymous()) {
return "";
}
if (lastLoginTimeMillis == 0) {
return "Never";
}
PrettyTime prettyTime = new PrettyTime();
return prettyTime.format(new Date(lastLoginTimeMillis));
}
示例12: getLastAccessString
import org.ocpsoft.prettytime.PrettyTime; //導入方法依賴的package包/類
public String getLastAccessString() {
if (isAnonymous() || (lastAccessTimeMillis == 0)) {
return "N/A";
}
PrettyTime prettyTime = new PrettyTime();
Date lastAccessDate = new Date(lastAccessTimeMillis);
return prettyTime.format(lastAccessDate) + " (" + lastAccessDate.toString() + ")";
}
示例13: StatsTabPanel
import org.ocpsoft.prettytime.PrettyTime; //導入方法依賴的package包/類
public StatsTabPanel(String id, ItemInfo item) {
super(id);
LabeledValue downloadedLabel = new LabeledValue("downloaded", "Downloaded: ");
add(downloadedLabel);
LabeledValue lastDownloaded = new LabeledValue("lastDownloaded", "Last Downloaded: ");
add(lastDownloaded);
LabeledValue lastDownloadedBy = new LabeledValue("lastDownloadedBy", "Last Downloaded by: ");
add(lastDownloadedBy);
if (item.isFolder()) {
downloadedLabel.setVisible(false);
lastDownloaded.setVisible(false);
lastDownloadedBy.setVisible(false);
return;
}
StatsInfo statsInfo = repositoryService.getStatsInfo(item.getRepoPath());
if (statsInfo == null) {
statsInfo = InfoFactoryHolder.get().createStats();
}
long downloadCount = statsInfo.getDownloadCount();
downloadedLabel.setValue(Long.toString(downloadCount));
if (downloadCount == 0) {
//No download data available (either never downloaded or coming from legacy repo)
lastDownloaded.setVisible(false);
lastDownloadedBy.setVisible(false);
} else {
PrettyTime prettyTime = new PrettyTime();
Date lastDownloadedDate = new Date(statsInfo.getLastDownloaded());
String lastDownloadedString = prettyTime.format(lastDownloadedDate) +
" (" + lastDownloadedDate.toString() + ")";
lastDownloaded.setValue(lastDownloadedString);
String lastDownloadedByVal = statsInfo.getLastDownloadedBy();
lastDownloadedBy.setValue(StringUtils.hasLength(lastDownloadedByVal) ? lastDownloadedByVal : "");
}
}
示例14: onPostExecute
import org.ocpsoft.prettytime.PrettyTime; //導入方法依賴的package包/類
@Override
protected void onPostExecute(Grade[] grades) {
if (grades != null) {
PrettyTime prettyTime = new PrettyTime(new Locale("nl"));
List<Item> itemList = new ArrayList<>();
for (Grade grade : grades) {
String string1 = grade.subject.name;
string1 = string1.substring(0, 1).toUpperCase() + string1.substring(1);
String string2 = grade.grade;
String string3 = grade.subject.abbreviation;
String string4 = prettyTime.format(grade.filledInDate);
boolean isSufficient = Float.parseFloat(string2.replaceAll(",", ".")) >= 5.5f;
if (isSufficient) {
itemList.add(new Item(string1, string2, string3, string4));
} else {
itemList.add(new Item(string1, string2, string3, string4, "#86FF0000"));
}
}
if (itemList.isEmpty()) {
itemList.add(new Item(getActivity().getString(R.string.no_appointments)));
}
LinearLayout gradesLayout = (LinearLayout) getTabFragment().view.findViewById(R.id.recent_grades_container);
getTabFragment().populateLayout(gradesLayout, new ItemAdapter(itemList));
} else {
Snackbar.make(getTabFragment().view, getActivity().getString(R.string.no_internet), Snackbar.LENGTH_LONG);
}
getTabFragment().swipeRefresh.setRefreshing(false);
}
示例15: getActualTime
import org.ocpsoft.prettytime.PrettyTime; //導入方法依賴的package包/類
public static String getActualTime(String createdAt) {
String dateStart = (createdAt.contains("T")) ? formatdate(createdAt) : createdAt;
SimpleDateFormat format = new SimpleDateFormat("MMM dd, yyyy hh:mm:ss a", Locale.ENGLISH);
Date d1 = null;
Date d2 = new Date();
try {
d1 = format.parse(dateStart);
//d2 = format.parse(current_date);
} catch (java.text.ParseException e) {
e.printStackTrace();
}
long diff = d2.getTime() - d1.getTime();
long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000);
long min = (diffHours * 60) + diffMinutes + (diffSeconds / 60);
PrettyTime p = new PrettyTime();
String currentTime = p.format(new Date(System.currentTimeMillis() - 1000 * 60 * min));
if (currentTime.equalsIgnoreCase("moments from now")) {
return currentTime.replaceAll(currentTime, "just now");
}
if (currentTime.equalsIgnoreCase("moments ago")) {
return currentTime.replaceAll(currentTime, "1 minute ago");
}
return currentTime;
}