本文整理汇总了Java中org.joda.time.DateTime.getYear方法的典型用法代码示例。如果您正苦于以下问题:Java DateTime.getYear方法的具体用法?Java DateTime.getYear怎么用?Java DateTime.getYear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.DateTime
的用法示例。
在下文中一共展示了DateTime.getYear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Calendar
import org.joda.time.DateTime; //导入方法依赖的package包/类
public Calendar(DateTime firstMonth, DateTime lastMonth) {
this.firstMonth = firstMonth;
this.firstDayOfWeek = java.util.Calendar.getInstance(Locale.getDefault()).getFirstDayOfWeek();
DateTime startMonth = firstMonth.plusMonths(1);
int monthsBetweenCount = Months.monthsBetween(firstMonth, lastMonth).getMonths();
months = new ArrayList<>();
months.add(firstMonth);
currentMonth = firstMonth;
DateTime monthToAdd = new DateTime(startMonth.getYear(), startMonth.getMonthOfYear(), 1, 0, 0);
for (int i = 0; i <= monthsBetweenCount; i++) {
months.add(monthToAdd);
monthToAdd = monthToAdd.plusMonths(1);
}
}
示例2: isTheSameDay
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 是否同一天 年月日是否一致
*
* @param date1
* @param date2
* @return
*/
public static boolean isTheSameDay(@Nullable Date date1,@Nullable Date date2) {
if(Check.isNullObjects(date1,date2)){
return false;
}
DateTime dateTime1 = new DateTime(date1);
DateTime dateTime2 = new DateTime(date2);
//年份是否一样
if (dateTime1.getYear() != dateTime2.getYear()) {
return false;
}
//日期是否一样
if (dateTime1.getDayOfYear() != dateTime2.getDayOfYear()) {
return false;
}
return true;
}
示例3: testCurrentTime
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 获取当前时间
* 本月几号
* 获取月份
* 获取年份
*/
@Test
public void testCurrentTime() {
// 获取当前时间
DateTime dt = new DateTime();
String currentTime = dt.toString("yyyy-MM-dd HH:mm:ss");
System.out.println("currentTime: " + currentTime);
// 获取当前月的几号
int day = dt.getDayOfMonth();
System.out.println("day: " + day);
// 获取当年的月份
int month = dt.getMonthOfYear();
System.out.println("month: " + month);
// 获取年份
int year = dt.getYear();
System.out.println("year: " + year);
}
示例4: getAvailableUploadId
import org.joda.time.DateTime; //导入方法依赖的package包/类
public static String getAvailableUploadId(){
StringBuilder sb = new StringBuilder();
// Send all output to the Appendable object sb
Formatter formatter = new Formatter(sb);
java.util.Date juDate = new Date();
DateTime dt = new DateTime(juDate);
int day = dt.getDayOfMonth();
int month = dt.getMonthOfYear();
int year = dt.getYear();
int hour = dt.getHourOfDay();
int minute = dt.getMinuteOfHour();
int seconds = dt.getSecondOfMinute();
formatter.format("%d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, seconds);
return sb.toString();
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-3-sixguysburgers-fries,代码行数:21,代码来源:ImageHandler.java
示例5: addMonthView
import org.joda.time.DateTime; //导入方法依赖的package包/类
private void addMonthView() {
View calendar = LayoutInflater.from(getContext()).inflate(R.layout.layout_calendar_content, this, false);
calendar.setLayoutParams(new LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, calendarHeight));
viewPagerContent = (ViewPager) calendar.findViewById(R.id.viewpager_calendar);
addView(calendar);
DateTime startDay = new DateTime();
calendarPagerAdapter = new CalendarPagerAdapter(getContext(), calendarHeight, startDay.getYear(), startDay.getMonthOfYear(), getViewHelper);
viewPagerContent.setAdapter(calendarPagerAdapter);
viewPagerContent.setCurrentItem(CENTER_POSITION);
}
示例6: parseTime
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 解析API传回的时间 XXXX-XX-XX 的字符串, 转换为中文指代的时间, 比如 "今天 02/09"
*/
public static String parseTime(String timeText){
DateTime dateTime = new DateTime();
String[] time = timeText.split("-");
int currentMonth = dateTime.getMonthOfYear();
int currentDay = dateTime.getDayOfMonth();
int currentWeak = dateTime.getDayOfWeek();
int currentYear = dateTime.getYear();
int month = Integer.parseInt(time[1]);
int day = Integer.parseInt(time[2]);
int year = Integer.parseInt(time[0]);
int offset = 0; // 相差量
if (year == currentYear){
//如果是同一年:
if (month == currentMonth){
// 如果是同一个月
offset = day - currentDay;
}else{
offset = day + parseMonth(currentMonth, currentYear) - currentDay;
}
}else{
offset = 31 - currentDay + day;
}
String monthAndDay = time[1] + "/" + time[2];
if (offset == 0) return "今天 " + monthAndDay;
if (offset == 1) return "明天 " + monthAndDay;
return parseWeak(currentWeak + offset) + " " + monthAndDay;
}
示例7: formatDate
import org.joda.time.DateTime; //导入方法依赖的package包/类
private String formatDate (DateTime beg, DateTime end) {
if (beg.getYear() != end.getYear())
return longFormat.print(beg) + "-" + longFormat.print(end);
if (beg.getMonthOfYear() != end.getMonthOfYear())
return medFormat.print(beg) + "-" + medFormat.print(end) + ", " + beg
.getYear();
return shortFormat.print(beg) + " " + beg.getDayOfMonth() + "-" +
end.getDayOfMonth() + ", " + beg.getYear();
}
示例8: getDateIdFromTimestamp
import org.joda.time.DateTime; //导入方法依赖的package包/类
public static int getDateIdFromTimestamp(long millis) {
int result;
DateTime dt = new DateTime(millis, DateTimeZone.UTC);
int year = dt.getYear();
int month = dt.getMonthOfYear();
int day = dt.getDayOfMonth();
result = day + (100 * month) + (10000 * year);
return result;
}
示例9: separateByDate
import org.joda.time.DateTime; //导入方法依赖的package包/类
private List<RevCommit> separateByDate(List<RevCommit> commits) {
List<RevCommit> separated = new ArrayList<>();
DateTime groupTime = null;
for (RevCommit commit: commits) {
DateTime commitTime = new DateTime(commit.getCommitterIdent().getWhen());
if (groupTime == null || commitTime.getYear() != groupTime.getYear()
|| commitTime.getDayOfYear() != groupTime.getDayOfYear()) {
groupTime = commitTime;
separated.add(null);
}
separated.add(commit);
}
return separated;
}
示例10: parseTime
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 输入时间 XXXX-XX-XX 的字符串, 放回中文指代的时间, 比如 "今天 02/09"
*/
public static String parseTime(String timeText){
DateTime dateTime = new DateTime();
String[] time = timeText.split("-");
int currentMonth = dateTime.getMonthOfYear();
int currentDay = dateTime.getDayOfMonth();
int currentWeak = dateTime.getDayOfWeek();
int currentYear = dateTime.getYear();
int month = Integer.parseInt(time[1]);
int day = Integer.parseInt(time[2]);
int year = Integer.parseInt(time[0]);
int offset = 0; // 相差量
if (year == currentYear){
//如果是同一年:
if (month == currentMonth){
// 如果是同一个月
offset = day - currentDay;
}else{
offset = day + parseMonth(currentMonth, currentYear) - currentDay;
}
}else{
offset = 31 - currentDay + day;
}
String monthAndDay = time[1] + "/" + time[2];
if (offset == 0) return "今天 " + monthAndDay;
if (offset == 1) return "明天 " + monthAndDay;
return parseWeak(currentWeak + offset) + " " + monthAndDay;
}
示例11: isThisMonth
import org.joda.time.DateTime; //导入方法依赖的package包/类
public static boolean isThisMonth(DateTime current, DateTime t2){
return (current.getYear() == t2.getYear()) && (current.getMonthOfYear() == t2.getMonthOfYear());
}
示例12: testDateWithoutOrigin
import org.joda.time.DateTime; //导入方法依赖的package包/类
public void testDateWithoutOrigin() throws Exception {
DateTime dt = new DateTime(DateTimeZone.UTC);
assertAcked(prepareCreate("test").addMapping(
"type1",
jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("test").field("type", "text")
.endObject().startObject("num1").field("type", "date").endObject().endObject().endObject().endObject()));
DateTime docDate = dt.minusDays(1);
String docDateString = docDate.getYear() + "-" + String.format(Locale.ROOT, "%02d", docDate.getMonthOfYear()) + "-"
+ String.format(Locale.ROOT, "%02d", docDate.getDayOfMonth());
client().index(
indexRequest("test").type("type1").id("1")
.source(jsonBuilder().startObject().field("test", "value").field("num1", docDateString).endObject())).actionGet();
docDate = dt.minusDays(2);
docDateString = docDate.getYear() + "-" + String.format(Locale.ROOT, "%02d", docDate.getMonthOfYear()) + "-"
+ String.format(Locale.ROOT, "%02d", docDate.getDayOfMonth());
client().index(
indexRequest("test").type("type1").id("2")
.source(jsonBuilder().startObject().field("test", "value").field("num1", docDateString).endObject())).actionGet();
docDate = dt.minusDays(3);
docDateString = docDate.getYear() + "-" + String.format(Locale.ROOT, "%02d", docDate.getMonthOfYear()) + "-"
+ String.format(Locale.ROOT, "%02d", docDate.getDayOfMonth());
client().index(
indexRequest("test").type("type1").id("3")
.source(jsonBuilder().startObject().field("test", "value").field("num1", docDateString).endObject())).actionGet();
refresh();
ActionFuture<SearchResponse> response = client().search(
searchRequest().searchType(SearchType.QUERY_THEN_FETCH).source(
searchSource().query(
functionScoreQuery(QueryBuilders.matchAllQuery(), new FilterFunctionBuilder[]{
new FilterFunctionBuilder(linearDecayFunction("num1", null, "7000d")),
new FilterFunctionBuilder(gaussDecayFunction("num1", null, "1d")),
new FilterFunctionBuilder(exponentialDecayFunction("num1", null, "7000d"))
}).scoreMode(FiltersFunctionScoreQuery.ScoreMode.MULTIPLY))));
SearchResponse sr = response.actionGet();
assertNoFailures(sr);
SearchHits sh = sr.getHits();
assertThat(sh.getHits().length, equalTo(3));
double[] scores = new double[4];
for (int i = 0; i < sh.getHits().length; i++) {
scores[Integer.parseInt(sh.getAt(i).getId()) - 1] = sh.getAt(i).getScore();
}
assertThat(scores[1], lessThan(scores[0]));
assertThat(scores[2], lessThan(scores[1]));
}
示例13: isTomorrow
import org.joda.time.DateTime; //导入方法依赖的package包/类
private boolean isTomorrow(Event event) {
DateTime start = event.getStart();
DateTime tomorrow = DateTime.now().plusDays(1);
return start.getDayOfYear() == tomorrow.getDayOfYear() && start.getYear() == tomorrow.getYear();
}
示例14: formatted
import org.joda.time.DateTime; //导入方法依赖的package包/类
private String formatted(DateTime d) {
return d.monthOfYear().getAsShortText(Locale.getDefault()) + " " +
d.getDayOfMonth() + ", " + d.getYear();
}
示例15: getCurrentSchoolYear
import org.joda.time.DateTime; //导入方法依赖的package包/类
public static int getCurrentSchoolYear() {
DateTime dateTime = new DateTime();
return dateTime.getMonthOfYear() <= 8 ? dateTime.getYear() - 1 : dateTime.getYear();
}