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


Java DateTime.getYear方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:MOLO17,项目名称:CustomizableCalendar,代码行数:19,代码来源:Calendar.java

示例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;
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:24,代码来源:DateCalculator.java

示例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);
}
 
开发者ID:cbooy,项目名称:cakes,代码行数:26,代码来源:JodaTimeDemo1.java

示例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);
}
 
开发者ID:LineChen,项目名称:Month_Calendar,代码行数:11,代码来源:MonthCalendar.java

示例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;

}
 
开发者ID:LynnYuki,项目名称:CoolCloud-Weather,代码行数:41,代码来源:Time.java

示例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();

}
 
开发者ID:gvsucis,项目名称:mobile-app-dev-book,代码行数:11,代码来源:TripMapFragment.java

示例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;
}
 
开发者ID:GoogleCloudPlatform,项目名称:dataflow-opinion-analysis,代码行数:10,代码来源:IndexerPipelineUtils.java

示例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;
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:15,代码来源:CommitListPanel.java

示例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;

}
 
开发者ID:lentitude,项目名称:BS-Weather,代码行数:41,代码来源:Time.java

示例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());
}
 
开发者ID:LineChen,项目名称:Month_Calendar,代码行数:4,代码来源:CalendarUtil.java

示例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]));

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:51,代码来源:DecayFunctionScoreIT.java

示例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();
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:7,代码来源:SpeechService.java

示例14: formatted

import org.joda.time.DateTime; //导入方法依赖的package包/类
private String formatted(DateTime d) {
    return d.monthOfYear().getAsShortText(Locale.getDefault()) + " " +
            d.getDayOfMonth() + ", " + d.getYear();
}
 
开发者ID:gvsucis,项目名称:mobile-app-dev-book,代码行数:5,代码来源:TripEditorActivity.java

示例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();
}
 
开发者ID:wulkanowy,项目名称:wulkanowy,代码行数:5,代码来源:TimeUtils.java


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