java.util.Date#setYear ( )源码实例Demo

下面列出了java.util.Date#setYear ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = context.getLayoutInflater();
    View listViewItem = inflater.inflate(R.layout.layout_appointment_list, null, true);

    TextView textViewName = (TextView) listViewItem.findViewById(R.id.clinicName);
    TextView textViewDate = (TextView) listViewItem.findViewById(R.id.dateTime);
    TextView textViewService = (TextView) listViewItem.findViewById(R.id.clinicService);

    Booking booking = bookings.get(position);
    textViewName.setText(booking.getClinic().getName());
    String pattern = "yyyy-MM-dd HH:mm ";
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
    Date showDate = new Date();
    showDate.setHours(booking.getTime().getHours());
    showDate.setMinutes(booking.getTime().getMinutes());
    showDate.setDate(booking.getTime().getDate());
    showDate.setMonth(booking.getTime().getMonth());
    showDate.setYear(booking.getTime().getYear());

    String date = simpleDateFormat.format(showDate);
    textViewDate.setText(date);
    textViewService.setText(booking.getService().getName());
    return listViewItem;
}
 
源代码2 项目: MuslimMateAndroid   文件: WeatherAdapter.java
@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));
}
 
源代码3 项目: MiBandDecompiled   文件: cg.java
protected String a(SportDay sportday)
{
    Date date = new Date();
    SimpleDateFormat simpledateformat = new SimpleDateFormat();
    if (sportday.equals(StatisticFragment.C(q)))
    {
        return s;
    }
    if (sportday.offsetDay(StatisticFragment.C(q)) == -1 && !StatisticFragment.D(q))
    {
        return t;
    }
    if (1 + sportday.mon == 1 && sportday.day == 1)
    {
        date.setYear(sportday.year);
        date.setMonth(sportday.mon);
        date.setDate(sportday.day);
        simpledateformat.applyPattern(v);
    } else
    {
        date.setMonth(sportday.mon);
        date.setDate(sportday.day);
        simpledateformat.applyPattern(u);
    }
    return simpledateformat.format(date);
}
 
public void testGetInvalidityDate() throws Exception {
    CertificateRevokedException exception = getTestException();

    Date firstDate = exception.getInvalidityDate();
    assertNotSame(firstDate, exception.getInvalidityDate());

    firstDate.setYear(firstDate.getYear() + 1);
    assertTrue(firstDate.compareTo(exception.getInvalidityDate()) > 0);
}
 
源代码5 项目: astor   文件: DateTimePerformance.java
private void checkDateSetGetYear() {
    int COUNT = COUNT_FAST;
    Date dt = new Date();
    for (int i = 0; i < AVERAGE; i++) {
        start("Date", "setGetYear");
        for (int j = 0; j < COUNT; j++) {
            dt.setYear(1972);
            int val = dt.getYear();
            if (val < 0) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
源代码6 项目: soapui-pro-crack   文件: LicenseHandling.java
@SuppressWarnings("deprecation")
public static License xxxxx(){
	License l = new License();
	l.addFeature("organization", "yisufuyou-org");
	l.addFeature("name", "yisufyou-name");
	l.addFeature("type", LicenseType.PROFESSIONAL.name());
	Date d = new Date();
	d.setYear(2114);
	l.addFeature("expiration", d);
	l.addFeature("id", "yisufuyou-id");
	return l;
}
 
源代码7 项目: javacore   文件: MutablePeriod.java
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);
}
 
源代码8 项目: javacore   文件: MutablePeriod.java
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);
}
 
源代码9 项目: MiBandDecompiled   文件: SportDay.java
public String formatStringDay()
{
    Date date = new Date();
    date.setYear(-1900 + year);
    date.setMonth(mon);
    date.setDate(day);
    return (new SimpleDateFormat(BraceletApp.getContext().getString(0x7f0d0055))).format(date);
}
 
源代码10 项目: j2objc   文件: DateTest.java
/**
 * java.util.Date#setYear(int)
 */
public void test_setYearI() {
    // Test for method void java.util.Date.setYear(int)
    Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
            .getTime();
    d.setYear(8);
    assertEquals("Set incorrect year", 8, d.getYear());
}
 
源代码11 项目: JavaSCR   文件: MutablePeriod.java
@SuppressWarnings("deprecation")
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);
}
 
源代码12 项目: datacollector   文件: TimeNowEL.java
@ElFunction(prefix = TIME_CONTEXT_VAR, name = "trimDate", description = "Set date portion of datetime expression to January 1, 1970")
@SuppressWarnings("deprecation")
public static Date trimDate(@ElParam("datetime") Date in) {
  if(in == null) {
    return null;
  }

  Date ret = new Date(in.getTime());
  ret.setYear(70);
  ret.setMonth(0);
  ret.setDate(1);
  return ret;
}
 
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = context.getLayoutInflater();
    listViewItem = inflater.inflate(R.layout.layout_appointment_finished_list, null, true);

    rated = false;

    TextView textViewName = (TextView) listViewItem.findViewById(R.id.clinicName);
    TextView textViewService = (TextView) listViewItem.findViewById(R.id.clinicService);
    TextView textViewTime = (TextView) listViewItem.findViewById(R.id.dateTime);

    Booking booking = bookings.get(position);
    clinic = booking.getClinic();
    DataBaseService service = booking.getService();
    textViewName.setText(clinic.getName());
    textViewService.setText(service.getName());
    String pattern = "yyyy-MM-dd HH:mm ";
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
    Date showDate = new Date();
    showDate.setHours(booking.getTime().getHours());
    showDate.setMinutes(booking.getTime().getMinutes());
    showDate.setDate(booking.getTime().getDate());
    showDate.setMonth(booking.getTime().getMonth());
    showDate.setYear(booking.getTime().getYear());

    String date = simpleDateFormat.format(showDate);
    textViewTime.setText(date);

    Button rate = listViewItem.findViewById(R.id.rateBtn);

    if(booking.getRating()!=0){
        rate.setText("Rated: " + booking.getRating() + " Stars");
    }

    rate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showRatingDialog(position);
        }
    });


    return listViewItem;
}
 
源代码14 项目: freeacs   文件: ReportGeneratorTest.java
@Test
public void populateReportHWTable() throws SQLException {
  // Given:
  final Calendar calendar = Calendar.getInstance();
  calendar.set(Calendar.YEAR, 2018);
  calendar.set(Calendar.MONTH, 10);
  calendar.set(Calendar.DAY_OF_MONTH, 15);
  final ReportGenerator reportGenerator =
      new ReportGenerator("Test", ScheduleType.DAILY, null, null);
  final DataSource fakeDataSource = mock(DataSource.class);
  final Connection fakeConnection = mock(Connection.class);
  final PreparedStatement fakePreparedStatement = mock(PreparedStatement.class);
  when(fakeConnection.prepareStatement(anyString())).thenReturn(fakePreparedStatement);
  when(fakeDataSource.getConnection()).thenReturn(fakeConnection);
  final Report<RecordHardware> hardwareReport =
      new Report<>(RecordHardware.class, PeriodType.ETERNITY);
  final Date tms = new Date();
  tms.setYear(2018 - 1900);
  tms.setMonth(11 - 1);
  tms.setDate(1);
  final Key key =
      RecordHardware.keyFactory.makeKey(
          tms, PeriodType.DAY, "testunittype", "testprofile", "v1.0");
  final RecordHardware recordHardware =
      new RecordHardware(tms, PeriodType.DAY, "testunittype", "testprofile", "v1.0");
  hardwareReport.getMap().put(key, recordHardware);

  // When:
  reportGenerator.populateReportHWTable(fakeDataSource, hardwareReport, calendar);

  // Then:
  verify(fakeConnection)
      .prepareStatement(
          "insert into report_hw VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
  verify(fakePreparedStatement).executeUpdate();
  final long expectedTime = new TmsConverter(calendar).convert(tms, PeriodType.DAY).getTime();
  final Timestamp expectedTimestamp = new Timestamp(expectedTime);
  verify(fakePreparedStatement).setTimestamp(1, expectedTimestamp);
  verify(fakePreparedStatement).setInt(2, PeriodType.DAY.getTypeInt());
  verify(fakePreparedStatement).setString(3, "testunittype");
  verify(fakePreparedStatement).setString(4, "testprofile");
  verify(fakePreparedStatement).setString(5, "v1.0");
  verify(fakePreparedStatement).setInt(6, 0);
  verify(fakePreparedStatement).setInt(7, 0);
  verify(fakePreparedStatement).setInt(8, 0);
  verify(fakePreparedStatement).setInt(9, 0);
  verify(fakePreparedStatement).setInt(10, 0);
  verify(fakePreparedStatement).setInt(11, 0);
  verify(fakePreparedStatement).setInt(12, 0);
  verify(fakePreparedStatement).setInt(13, 0);
  verify(fakePreparedStatement).setInt(14, 0);
  verify(fakePreparedStatement).setInt(15, 0);
  verify(fakePreparedStatement).setString(16, null);
  verify(fakePreparedStatement).setString(17, null);
  verify(fakePreparedStatement).setString(18, null);
  verify(fakePreparedStatement).setString(19, null);
  verify(fakePreparedStatement).setString(20, null);
  verify(fakePreparedStatement).setString(21, null);
  verify(fakePreparedStatement).setString(22, null);
  verify(fakePreparedStatement).setString(23, null);
  verify(fakePreparedStatement).setString(24, null);
  verify(fakePreparedStatement).setString(25, null);
  verify(fakePreparedStatement).setString(26, null);
  verify(fakePreparedStatement).setString(27, null);
  verify(fakePreparedStatement).setString(28, null);
  verify(fakeConnection).close();
}
 
protected Date nextIntervalDate(Date intervalMinDate, DateIntervalType intervalType, int intervals) {
    Date intervalMaxDate = new Date(intervalMinDate.getTime());

    if (MILLENIUM.equals(intervalType)) {
        intervalMaxDate.setYear(intervalMinDate.getYear() + 1000 * intervals);
    }
    else if (CENTURY.equals(intervalType)) {
        intervalMaxDate.setYear(intervalMinDate.getYear() + 100 * intervals);
    }
    else if (DECADE.equals(intervalType)) {
        intervalMaxDate.setYear(intervalMinDate.getYear() + 10 * intervals);
    }
    else if (YEAR.equals(intervalType)) {
        intervalMaxDate.setYear(intervalMinDate.getYear() +  intervals);
    }
    else if (QUARTER.equals(intervalType)) {
        intervalMaxDate.setMonth(intervalMinDate.getMonth() + 3 * intervals);
    }
    else if (MONTH.equals(intervalType)) {
        intervalMaxDate.setMonth(intervalMinDate.getMonth() + intervals);
    }
    else if (WEEK.equals(intervalType)) {
        intervalMaxDate.setDate(intervalMinDate.getDate() + 7 * intervals);
    }
    else if (DAY.equals(intervalType) || DAY_OF_WEEK.equals(intervalType)) {
        intervalMaxDate.setDate(intervalMinDate.getDate() + intervals);
    }
    else if (HOUR.equals(intervalType)) {
        intervalMaxDate.setHours(intervalMinDate.getHours() + intervals);
    }
    else if (MINUTE.equals(intervalType)) {
        intervalMaxDate.setMinutes(intervalMinDate.getMinutes() + intervals);
    }
    else if (SECOND.equals(intervalType)) {
        intervalMaxDate.setSeconds(intervalMinDate.getSeconds() + intervals);
    }
    else {
        // Default to year to avoid infinite loops
        intervalMaxDate.setYear(intervalMinDate.getYear() + intervals);
    }
    return intervalMaxDate;
}
 
源代码16 项目: MOOC   文件: AdminController.java
@RequestMapping(value="banip")//封禁ip
public void banip(HttpServletResponse resp,HttpSession session,String ip,String mark,String time) throws IOException{
	User loginUser = (User) session.getAttribute("loginUser");
	if (loginUser == null) {
		return ;
	}else if(!"admin".equals(loginUser.getMission())){
		//添加管理员的再次验证
		return ;
	}
	Date date = new Date();
	Ipset ip1 = ipsetBiz.selectip(ip);
	boolean isnull = false;
	if(ip1==null) {
		ip1=new Ipset();
		ip1.setIp(ip);
		isnull =true;
	}
	ip1.setIp(ip);
	ip1.setMark(mark);
	ip1.setType("1");
	switch (time) {
		case "5m":
			if (date.getMinutes() > 55) {
				date.setMinutes(date.getMinutes() - 55);
				date.setHours(date.getHours() + 1);
			} else {
				date.setMinutes(date.getMinutes() + 5);
			}
			ip1.setBantime(date);
			break;
		case "2h":
			date.setHours(date.getHours() + 2);
			ip1.setBantime(date);
			break;
		case "1d":
			date.setDate(date.getDate() + 1);
			ip1.setBantime(date);
			break;
		case "1m":
			date.setMonth(date.getMonth() + 1);
			ip1.setBantime(date);
			break;
		case "1y":
			date.setYear(date.getYear() + 1);
			ip1.setBantime(date);
			break;
		case "ever":
			date.setYear(date.getYear() + 99);
			ip1.setBantime(date);
			break;
	}
	if(isnull) {
		ipsetBiz.insert(ip1);
	}else {
	ipsetBiz.updateByPrimaryKeySelective(ip1);
	}
	resp.setCharacterEncoding("utf-8");
	resp.getWriter().write("封禁成功!封禁至:"+date);
}
 
源代码17 项目: MOOC   文件: AdminController.java
@RequestMapping(value="banip")//封禁ip
public void banip(HttpServletResponse resp,HttpSession session,String ip,String mark,String time) throws IOException{
	Date date = new Date();
	Ipset ip1 = ipsetBiz.selectip(ip);
	boolean isnull = false;
	if(ip1==null) {
		ip1=new Ipset();
		ip1.setIp(ip);
		isnull =true;
	}
	ip1.setIp(ip);
	ip1.setMark(mark);
	ip1.setType("1");
	if(time.equals("5m")) {
		if(date.getMinutes()>55) {
			date.setMinutes(date.getMinutes()-55);
			date.setHours(date.getHours()+1);
		}else {
		date.setMinutes(date.getMinutes()+5);
		}
		ip1.setBantime(date);
	}else if(time.equals("2h")) {
		date.setHours(date.getHours()+2);
		ip1.setBantime(date);
	}else if(time.equals("1d")) {
		date.setDate(date.getDate()+1);
		ip1.setBantime(date);
	}else if(time.equals("1m")) {
		date.setMonth(date.getMonth()+1);
		ip1.setBantime(date);
	}else if(time.equals("1y")) {
		date.setYear(date.getYear()+1);
		ip1.setBantime(date);
	}else if(time.equals("ever")) {
		date.setYear(date.getYear()+99);
		ip1.setBantime(date);
	}
	if(isnull) {
		ipsetBiz.insert(ip1);
	}else {
	ipsetBiz.updateByPrimaryKeySelective(ip1);
	}
	resp.setCharacterEncoding("utf-8");
	resp.getWriter().write("封禁成功!封禁至:"+date);
}
 
源代码18 项目: ranger   文件: TestServiceDBStore.java
@Test
  public void test42getMetricByTypeaudits() throws Exception{
  	String type = "audits";
  	
  	Date date = new Date();
  	date.setYear(2018);
  
  	Mockito.when(restErrorUtil.parseDate(Mockito.anyString(),Mockito.anyString(),
                                       Mockito.any(), Mockito.any(), Mockito.anyString(),  Mockito.anyString())).thenReturn(date);
  	RangerServiceDefList svcDefList = new RangerServiceDefList();
  	svcDefList.setTotalCount(10l);
  	Mockito.when(serviceDefService.searchRangerServiceDefs(Mockito.any(SearchFilter.class))).thenReturn(svcDefList);
  	
  	
serviceDBStore.getMetricByType(type);


  }
 
源代码19 项目: SensorWebClient   文件: DataControlsTimeSeries.java
void changeMonth(int i) {

        Date begin = (Date) this.fromDateItem.getValue();
        Date end = (Date) this.toDateItem.getValue();

        int bMonth = begin.getMonth();
        int eMonth = end.getMonth();

        if (bMonth + i < 0) {
            bMonth = 11;
            begin.setYear(begin.getYear() - 1);
            begin.setMonth(bMonth);
        } else if (bMonth + i > 11) {
            bMonth = 0;
            begin.setYear(begin.getYear() + 1);
            begin.setMonth(bMonth);
        } else {
            bMonth += i;
            begin.setMonth(bMonth);
        }

        if (eMonth + i < 0) {
            eMonth = 11;
            end.setYear(end.getYear() - 1);
            end.setMonth(eMonth);
        } else if (eMonth + i > 11) {
            eMonth = 0;
            end.setYear(end.getYear() + 1);
            end.setMonth(eMonth);
        } else {
            eMonth += i;
            end.setMonth(eMonth);
        }

        if (datesAreValid(begin.getTime(), end.getTime())) {
            this.fromDateItem.setValue(begin);
            this.toDateItem.setValue(end);
            fireDateChangedEvent();

        } else {
            resetDatePicker();
        }

    }
 
源代码20 项目: che   文件: KubernetesDeploymentsTest.java
@BeforeMethod
public void setUp() throws Exception {
  lenient().when(clientFactory.create(anyString())).thenReturn(kubernetesClient);

  lenient().when(pod.getStatus()).thenReturn(status);
  lenient().when(pod.getMetadata()).thenReturn(metadata);
  lenient().when(metadata.getName()).thenReturn(POD_NAME);

  // Model DSL: client.pods().inNamespace(...).withName(...).get().getMetadata().getName();
  lenient().doReturn(podsMixedOperation).when(kubernetesClient).pods();
  lenient().doReturn(podsNamespaceOperation).when(podsMixedOperation).inNamespace(anyString());
  lenient().doReturn(podResource).when(podsNamespaceOperation).withName(anyString());
  lenient().doReturn(pod).when(podResource).get();

  // Model DSL:
  // client.apps().deployments(...).inNamespace(...).withName(...).get().getMetadata().getName();
  lenient().doReturn(apps).when(kubernetesClient).apps();
  lenient().doReturn(deploymentsMixedOperation).when(apps).deployments();
  lenient()
      .doReturn(deploymentsNamespaceOperation)
      .when(deploymentsMixedOperation)
      .inNamespace(anyString());
  lenient()
      .doReturn(deploymentResource)
      .when(deploymentsNamespaceOperation)
      .withName(anyString());
  lenient().doReturn(deployment).when(deploymentResource).get();
  lenient().doReturn(deploymentMetadata).when(deployment).getMetadata();
  lenient().doReturn(deploymentSpec).when(deployment).getSpec();

  // Model DSL: client.events().inNamespace(...).watch(...)
  //            event.getInvolvedObject().getKind()
  when(kubernetesClient.events()).thenReturn(eventMixedOperation);
  when(eventMixedOperation.inNamespace(any())).thenReturn(eventNamespaceMixedOperation);
  lenient().when(event.getInvolvedObject()).thenReturn(objectReference);
  lenient().when(event.getMetadata()).thenReturn(new ObjectMeta());
  // Workaround to ensure mocked event happens 'after' watcher initialisation.
  Date futureDate = new Date();
  futureDate.setYear(3000);
  lenient()
      .when(event.getLastTimestamp())
      .thenReturn(PodEvents.convertDateToEventTimestamp(futureDate));

  kubernetesDeployments =
      new KubernetesDeployments("namespace", "workspace123", clientFactory, executor);
}