當前位置: 首頁>>代碼示例>>Java>>正文


Java Date.setYear方法代碼示例

本文整理匯總了Java中java.util.Date.setYear方法的典型用法代碼示例。如果您正苦於以下問題:Java Date.setYear方法的具體用法?Java Date.setYear怎麽用?Java Date.setYear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Date的用法示例。


在下文中一共展示了Date.setYear方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onBindViewHolder

import java.util.Date; //導入方法依賴的package包/類
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    Weather weather = weatherList.get(position);
    String[] time = weather.dayName.split(" ");
    String[] weatherTime = time[1].split(":");
    String[] date = time[0].split("-");
    SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
    Date d = new Date();
    d.setYear(Integer.parseInt(date[0]));
    d.setMonth(Integer.parseInt(date[1]) - 1);
    d.setDate(Integer.parseInt(date[2]) - 1);
    String dayOfTheWeek = sdf.format(d);
    Log.d("DAY", weather.dayName + " : " + dayOfTheWeek);
    holder.dayName.setText(NumbersLocal.convertNumberType(context, weatherTime[0] + ":" + weatherTime[1] + ""));
    holder.weather.setText(NumbersLocal.convertNumberType(context, weather.tempMini + "°"));
    holder.image.setImageResource(WeatherIcon.get_icon_id_white(weather.image));
}
 
開發者ID:fekracomputers,項目名稱:MuslimMateAndroid,代碼行數:18,代碼來源:WeatherAdapter.java

示例2: showDate

import java.util.Date; //導入方法依賴的package包/類
/**
 * Function to show saved weather
 *
 * @param weathers Saved weathers
 * @param position Position
 * @param temp     Temp text view
 * @param image    Weather view
 * @param day      Day of week text view
 */
public void showDate(List<mindtrack.muslimorganizer.model.Weather> weathers, int position
        , TextView temp, ImageView image, TextView day) {
    try {
        mindtrack.muslimorganizer.model.Weather weather = weathers.get(position);
        String[] time = weather.dayName.split(" ");
        String[] date = time[0].split("-");
        SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
        Date d = new Date();
        d.setYear(Integer.parseInt(date[0]));
        d.setMonth(Integer.parseInt(date[1]) - 1);
        d.setDate(Integer.parseInt(date[2]) - 1);
        String dayOfTheWeek = sdf.format(d);
        day.setText(dayOfTheWeek);
        image.setImageResource(WeatherIcon.get_icon_id_white(weather.image));
        temp.setText(NumbersLocal.convertNumberType(getContext(), "°" + weather.tempMax + " | " + weather.tempMini + "°"));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:fekracomputers,項目名稱:MuslimMateAndroid,代碼行數:29,代碼來源:WeatherFragment.java

示例3: generateRandomDateTime

import java.util.Date; //導入方法依賴的package包/類
public Date generateRandomDateTime(){
    Date date = new Date();
    int year = randBetween(year_min-1900, year_max-1900);
    int month = randBetween(month_min, month_max);
    int day = randBetween(day_min, day_max);
    int hour = randBetween(hour_min, hour_max);
    int minute = randBetween(minute_min, minute_max);
    int second = randBetween(second_min, second_max);
    
    date.setYear(year);
    date.setMonth(month);
    date.setDate(day);
    date.setHours(hour);
    date.setMinutes(minute);
    date.setSeconds(second);
   
    return date;
}
 
開發者ID:faclc4,項目名稱:HTAPBench,代碼行數:19,代碼來源:RandomParameters.java

示例4: Date

import java.util.Date; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@ActionLayout(named = "Dias restantes para el cumpleaños", cssClassFa = "fa-birthday-cake")
public long calcularDiasRestantesParaCumpleaños() {
	Calendar hoyCal = Calendar.getInstance();
	Date hoyDate = hoyCal.getTime();
	Date cumpleaños = new Date();
	long cant;
	cumpleaños.setDate(this.getClienteFechaNacimiento().getDate());
	cumpleaños.setMonth(this.getClienteFechaNacimiento().getMonth());
	cumpleaños.setYear(hoyDate.getYear());
	if (cumpleaños.before(hoyDate)) {
		cumpleaños.setYear(cumpleaños.getYear() + 1);
	}
	cant = getDifferenceDays(hoyDate, cumpleaños);
	return cant;
}
 
開發者ID:leandrogonqn,項目名稱:Proyecto2017Seguros,代碼行數:17,代碼來源:Cliente.java

示例5: ok_actionPerformed

import java.util.Date; //導入方法依賴的package包/類
private void ok_actionPerformed(ActionEvent e) {
	Date d = (Date)date.getValue();
	Date start = (Date)timeStart.getValue();
	Date stop = (Date)timeStop.getValue();
	start.setYear(d.getYear());
	start.setMonth(d.getMonth());
	start.setDate(d.getDate());
	stop.setYear(d.getYear());
	stop.setMonth(d.getMonth());
	stop.setDate(d.getDate());
	timeStart.setValue(start);
	timeStop.setValue(stop);
	this.dispose();
}
 
開發者ID:ser316asu,項目名稱:Neukoelln_SER316,代碼行數:15,代碼來源:TimeLogDialog.java

示例6: testFilterByComment

import java.util.Date; //導入方法依賴的package包/類
/** testing method(s): part of HabitFilterByType(), It will
 * test can we filter habits by comment?
 */
@Test
public void testFilterByComment(){
    //We create two new habits,
    String title = "Habit1";
    String reason = "Reason1";
    Date date = new Date();
    List<Integer> days = Arrays.asList(1,2,3);
    Habit habit = new Habit(title, reason, date, days, "");
    String title2 = "Habit2";
    String reason2 = "Reason2";
    Date date2 = new Date();
    date2.setYear(2100);
    List<Integer> days2 = Arrays.asList(1,2,3);
    Habit habit2 = new Habit(title2, reason2, date2, days2, "");
    // We set comments
    habit.setReason("1");
    habit2.setReason("2");

    GregorianCalendar calendar = new GregorianCalendar();
    calendar.set(1856, 1, 1);
    habit.addHabitEvent(new HabitEvent("xyz", calendar.getTime()));
    calendar.set(2105, 1, 1);
    habit.addHabitEvent(new HabitEvent("xyz2", calendar.getTime()));
    calendar.set(2085, 1, 9);
    habit.addHabitEvent(new HabitEvent("xyz21", calendar.getTime()));
    habit.addHabitEvent(new HabitEvent("xyz1"));
    habit2.addHabitEvent(new HabitEvent("1"));
    String name = "Test1";
    Profile profile = new Profile(name);
    // We add to new profile,
    profile.addHabit(habit);
    profile.addHabit(habit2);
    List<CompletedEventDisplay> habitList = profile.getHabitHistory("1");
    assertTrue(habitList.size() == 3);
    assertTrue(profile.getHabitHistory("o").size() == 0);
    assertTrue(habitList.get(0).getCompletionDate().getTime() > habitList.get(1).getCompletionDate().getTime());
}
 
開發者ID:CMPUT301F17T15,項目名稱:CIA,代碼行數:41,代碼來源:HabitHistoryTests.java

示例7: getAge

import java.util.Date; //導入方法依賴的package包/類
/**根據生日獲取年齡
 * @param birthday
 * @return
 */
public static int getAge(Date birthday) {
	if (birthday == null) {
		return 0;
	}
	if (birthday.getYear() > getDateDetail(System.currentTimeMillis())[0]) {
		birthday.setYear(birthday.getYear() - TimeUtil.SYSTEM_START_DATE[0]);
	}

	return getAge(new int[]{birthday.getYear(), birthday.getMonth(), birthday.getDay()});
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:15,代碼來源:TimeUtil.java

示例8: getSmartBirthday

import java.util.Date; //導入方法依賴的package包/類
/**
 * @param birthday
 * @return
 */
public static String getSmartBirthday(Date birthday) {
	if (birthday == null) {
		return "";
	}
	if (birthday.getYear() > getDateDetail(System.currentTimeMillis())[0]) {
		birthday.setYear(birthday.getYear() - TimeUtil.SYSTEM_START_DATE[0]);
	}

	return getSmartBirthday(birthday.getTime(), false) + " " + (TimeUtil
			.getDateDetail(System.currentTimeMillis())[0] - birthday.getYear()) + "歲";
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:TimeUtil.java

示例9: main

import java.util.Date; //導入方法依賴的package包/類
public static void main(String[] args) {
	MutablePeriod mp = new MutablePeriod();
	Period p = mp.period;
	Date pEnd = mp.end;

	// Let's turn back the clock
	pEnd.setYear(78);
	System.out.println(p);

	// Bring back the 60s!
	pEnd.setYear(69);
	System.out.println(p);
}
 
開發者ID:turoDog,項目名稱:effectiveJava,代碼行數:14,代碼來源:MutablePeriod.java

示例10: testFilterByType

import java.util.Date; //導入方法依賴的package包/類
/** testing method(s): part of HabitFilterByType(), It will
 * test can we filter habits by type?
 */
@Test
public void testFilterByType(){
    // We create two new habits.
    String title = "Habit1";
    String reason = "Reason1";
    Date date = new Date();
    List<Integer> days = Arrays.asList(1,2,3);
    Habit habit = new Habit(title, reason, date, days, "");
    String title2 = "Habit2";
    String reason2 = "Reason2";
    Date date2 = new Date();
    date2.setYear(1856);
    List<Integer> days2 = Arrays.asList(1,2,3);
    Habit habit2 = new Habit(title2, reason2, date2, days2, "");
    // We set types,
    habit.setType("1");
    habit2.setType("2");
    String name = "Test1";
    // We add them to the new profile,
    Profile profile = new Profile(name);
    profile.addHabit(habit);
    profile.addHabit(habit2);
    List<CompletedEventDisplay> habitList = profile.getHabitHistory(habit);
    // We assert there is true or not.
    assertTrue(habitList.size() == 0);

    Date date3 = new Date();
    date3.setYear(2105);

    GregorianCalendar calendar = new GregorianCalendar();
    calendar.set(1856, 1, 1);
    habit.addHabitEvent(new HabitEvent("xyz", calendar.getTime()));
    calendar.set(2105, 1, 1);
    habit.addHabitEvent(new HabitEvent("xyz2", calendar.getTime()));
    calendar.set(2085, 1, 9);
    habit.addHabitEvent(new HabitEvent("xyz21", calendar.getTime()));
    habit.addHabitEvent(new HabitEvent("xyz1"));
    habit2.addHabitEvent(new HabitEvent("1"));

    habitList = profile.getHabitHistory(habit);
    assertTrue(habitList.size() == 4);
    assertTrue(profile.getHabitHistory(habit2).size() == 1);
    assertTrue(habitList.get(0).getCompletionDate().getTime() > habitList.get(1).getCompletionDate().getTime());
}
 
開發者ID:CMPUT301F17T15,項目名稱:CIA,代碼行數:48,代碼來源:HabitHistoryTests.java


注:本文中的java.util.Date.setYear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。