Java Code Examples for java.util.Date#setMonth()

The following examples show how to use java.util.Date#setMonth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppointmentUpcomingList.java    From Walk-In-Clinic-Android-App with MIT License 6 votes vote down vote up
@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;
}
 
Example 2
Source File: StatisticDailyFragment.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
protected String formatDate(SportDay sportday)
{
    if (sportday.equals(mToday))
    {
        return getString(0x7f0d01b9);
    }
    if (sportday.addDay(1).equals(mToday) && !Locale.getDefault().toString().startsWith(Locale.ENGLISH.toString()))
    {
        return getString(0x7f0d005e);
    } else
    {
        SimpleDateFormat simpledateformat = new SimpleDateFormat(getString(0x7f0d0055));
        Date date = new Date();
        date.setMonth(sportday.mon);
        date.setDate(sportday.day);
        String s = simpledateformat.format(date);
        Object aobj[] = new Object[2];
        aobj[0] = s;
        aobj[1] = b[sportday.getWeek()];
        return getString(0x7f0d0057, aobj);
    }
}
 
Example 3
Source File: ch.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
protected String a(SportDay sportday)
{
    if (sportday.offsetMonth(StatisticFragment.C(q)) == 0)
    {
        return t;
    }
    if (sportday.offsetMonth(StatisticFragment.C(q)) == -1)
    {
        return u;
    }
    Date date = new Date();
    SimpleDateFormat simpledateformat = new SimpleDateFormat();
    if (1 + sportday.mon == 1)
    {
        date.setYear(sportday.year);
        date.setMonth(sportday.mon);
        simpledateformat.applyPattern(w);
        return simpledateformat.format(date);
    } else
    {
        date.setMonth(sportday.mon);
        simpledateformat.applyPattern(v);
        return simpledateformat.format(date);
    }
}
 
Example 4
Source File: WeatherFragment.java    From MuslimMateAndroid with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example 5
Source File: Solution.java    From JavaRush with MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
private static boolean isDateOdd(String date) {
  boolean bool;
  Date date1 = new Date(date);
  Date ms = new Date(date);
  ms.setHours(0);
  ms.setMinutes(0);
  ms.setSeconds(0);
  ms.setMonth(0);
  ms.setDate(1);
  long num = date1.getTime() - ms.getTime();
  long dayMs = 24 * 60 * 60 * 1000;
  int day = (int) (num / dayMs);
  bool = day % 2 == 0;
  return bool;
}
 
Example 6
Source File: DateTypeAdapter.java    From doov with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public Object fromString(FieldInfo info, String value) {
    int year = Integer.parseInt(value.substring(0, 4));
    int month = Integer.parseInt(value.substring(4, 6));
    int day = Integer.parseInt(value.substring(6, 8));

    Date date = new Date();
    date.setDate(day);
    date.setMonth(month - 1);
    date.setYear(year - 1900);
    date.setHours(0);
    date.setMinutes(0);
    date.setSeconds(0);
    return date;
}
 
Example 7
Source File: SportDay.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 8
Source File: DateTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.Date#setMonth(int)
 */
public void test_setMonthI() {
    // Test for method void java.util.Date.setMonth(int)
    Date d = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9)
            .getTime();
    d.setMonth(0);
    assertEquals("Set incorrect month", 0, d.getMonth());
}
 
Example 9
Source File: ClientIntervalBuilderDynamicDate.java    From dashbuilder with Apache License 2.0 5 votes vote down vote up
protected Date firstIntervalDate(DateIntervalType intervalType, Date minDate, ColumnGroup columnGroup) {
    Date intervalMinDate = new Date(minDate.getTime());
    if (YEAR.equals(intervalType)) {
        intervalMinDate.setMonth(0);
        intervalMinDate.setDate(1);
        intervalMinDate.setHours(0);
        intervalMinDate.setMinutes(0);
        intervalMinDate.setSeconds(0);
    }
    if (QUARTER.equals(intervalType)) {
        int currentMonth = intervalMinDate.getMonth();
        int firstMonthYear = columnGroup.getFirstMonthOfYear().getIndex();
        int rest = Quarter.getPositionInQuarter(firstMonthYear, currentMonth + 1);
        intervalMinDate.setMonth(currentMonth - rest);
        intervalMinDate.setDate(1);
        intervalMinDate.setHours(0);
        intervalMinDate.setMinutes(0);
        intervalMinDate.setSeconds(0);
    }
    if (MONTH.equals(intervalType)) {
        intervalMinDate.setDate(1);
        intervalMinDate.setHours(0);
        intervalMinDate.setMinutes(0);
        intervalMinDate.setSeconds(0);
    }
    if (DAY.equals(intervalType) || DAY_OF_WEEK.equals(intervalType) || WEEK.equals(intervalType)) {
        intervalMinDate.setHours(0);
        intervalMinDate.setMinutes(0);
        intervalMinDate.setSeconds(0);
    }
    if (HOUR.equals(intervalType)) {
        intervalMinDate.setMinutes(0);
        intervalMinDate.setSeconds(0);
    }
    if (MINUTE.equals(intervalType)) {
        intervalMinDate.setSeconds(0);
    }
    return intervalMinDate;
}
 
Example 10
Source File: TestWBJSONToFromObjectConverter.java    From cms with Apache License 2.0 5 votes vote down vote up
@Test
public void testJSONStringFromField()
{
	try
	{
		Integer intValue = 123;
		String objString = (String)Whitebox.invokeMethod(wbObjectfromJson, "JSONStringFromField", intValue, intValue.getClass());
		assertTrue(objString.compareTo("123") == 0);
		
		Long longValue = -1234L;
		objString = (String)Whitebox.invokeMethod(wbObjectfromJson, "JSONStringFromField", longValue, longValue.getClass());
		assertTrue(objString.compareTo("-1234") == 0);
		
		String stringValue = "abc";
		objString = (String)Whitebox.invokeMethod(wbObjectfromJson, "JSONStringFromField", stringValue, stringValue.getClass());
		assertTrue(objString.compareTo("abc") == 0);
	
		Date dateValue = new Date();
		dateValue.setYear(2012);
		dateValue.setMonth(1);
		objString = (String) Whitebox.invokeMethod(wbObjectfromJson, "JSONStringFromField", dateValue, dateValue.getClass());
		assertTrue(objString != null);
		
		long height = 31;
		objString = (String) Whitebox.invokeMethod(wbObjectfromJson, "JSONStringFromField", height, long.class);
		assertTrue(objString.compareTo("31") == 0);

		long width = 32;
		objString = (String) Whitebox.invokeMethod(wbObjectfromJson, "JSONStringFromField", width, int.class);
		assertTrue(objString.compareTo("32") == 0);

		
	} catch (Exception e)
	{
		assertTrue(false);
	}
}
 
Example 11
Source File: AlbianDateTime.java    From Albianj2 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static Date dateAddSeconds(int year, int month, int day, long second) {
    Date dt = new Date();
    dt.setYear(year - 1900);
    dt.setMonth(month - 1);
    dt.setDate(day);
    dt.setHours(0);
    dt.setMinutes(0);
    dt.setSeconds(0);
    Calendar rightNow = Calendar.getInstance();
    rightNow.setTime(dt);
    rightNow.add(Calendar.SECOND, (int) second);
    Date dt1 = rightNow.getTime();
    return dt1;
}
 
Example 12
Source File: TimeNowEL.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 13
Source File: MyMonth.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @param args
 */
@ExpectWarning("DMI,DLS")
public static void main(String[] args) {

    Date x = new Date();
    x.setMonth(12);
    x.setMonth(-1);

    String month = "January";

    System.out.println(month.toUpperCase());
    month = month.toUpperCase();
}
 
Example 14
Source File: SmsParser.java    From sms-ticket with Apache License 2.0 5 votes vote down vote up
private Date parseDate(String text, String datePattern, SimpleDateFormat sdf, SimpleDateFormat sdfTime,
                       Ticket ticket) {
    Matcher m = Pattern.compile(datePattern).matcher(text);
    if (m.find()) {
        String d = m.group(1);
        if (!isEmpty(d)) {
            d = d.replaceAll(";", "");

            for (int i = 0; i < 2; i++) {
                final Date date;
                try {
                    if (i == 0) {
                        date = sdf.parse(d); // full date/time
                    } else if (i == 1 && sdfTime != null) {
                        date = sdfTime.parse(d); // only time
                    } else {
                        break;
                    }
                } catch (Exception e) {
                    continue;
                }

                if (i == 1 && ticket != null && ticket.validFrom != null) {
                    final Date prevDate = ticket.validFrom;
                    date.setYear(prevDate.getYear());
                    date.setMonth(prevDate.getMonth());
                    date.setDate(prevDate.getDate());
                }

                return date;
            }
        }
    }

    throw new RuntimeException("Cannot parse date from the message " + text);
}
 
Example 15
Source File: SportDay.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public String formatString()
{
    Date date = new Date();
    date.setYear(-1900 + year);
    date.setMonth(mon);
    date.setDate(day);
    return (new SimpleDateFormat(BraceletApp.getContext().getString(0x7f0d005d))).format(date);
}
 
Example 16
Source File: AdminController.java    From MOOC with MIT License 4 votes vote down vote up
@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);
}
 
Example 17
Source File: AdminController.java    From MOOC with MIT License 4 votes vote down vote up
@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);
}
 
Example 18
Source File: TestBadMethodCalls.java    From huntbugs with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@AssertWarning("DateBadMonth")
public void testBadMonth(Date date) {
    date.setMonth(12);
}
 
Example 19
Source File: DMI_BAD_MONTH.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@ExpectWarning("DMI_BAD_MONTH")
void bug(Date date) {
    date.setMonth(12);
}
 
Example 20
Source File: AppointmentFinishedList.java    From Walk-In-Clinic-Android-App with MIT License 4 votes vote down vote up
@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;
}