List of usage examples for java.util Calendar setTime
public final void setTime(Date date)
Date
. From source file:Main.java
public static Date substractMinutes(Date date, int minutes) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.MINUTE, -minutes); Date result = calendar.getTime(); return result; }
From source file:Main.java
public static Intent newCalendarIntent(Context context, Date startDate, String title, String location, String note) {/* w w w .j a v a2 s. co m*/ Calendar cal = Calendar.getInstance(); cal.setTime(startDate); Intent intent = new Intent(Intent.ACTION_EDIT); intent.setType("vnd.android.cursor.item/event"); intent.putExtra("beginTime", cal.getTimeInMillis()); intent.putExtra("endTime", cal.getTimeInMillis() + 60 * 60 * 1000); intent.putExtra("allDay", true); //intent.putExtra("rrule", "FREQ=WEEKLY;COUNT="+numWeeks); //intent.putExtra("rrule", "FREQ=YEARLY"); intent.putExtra("title", title); intent.putExtra("eventLocation", location); intent.putExtra("description", note); //intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE); //intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY); return intent; }
From source file:Main.java
public static Date getEndFinanacialDate(Date taxdate) { Calendar calendar = Calendar.getInstance(); calendar.setTime(taxdate); int yr = calendar.get(Calendar.YEAR); calendar.set(yr, 11, 31);/*from www.j a va 2 s. c om*/ taxdate = calendar.getTime(); return taxdate; }
From source file:Main.java
public static int[] parseDate(String dateString) { try {/* w ww . java 2 s . co m*/ DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy"); formatter.setLenient(false); Date date = (Date) formatter.parse(dateString); Calendar cal = Calendar.getInstance(); cal.setTime(date); int[] dateInts = new int[3]; dateInts[0] = cal.get(Calendar.DAY_OF_MONTH); dateInts[1] = cal.get(Calendar.MONTH); dateInts[2] = cal.get(Calendar.YEAR); return dateInts; } catch (Exception e) { throw new RuntimeException( "Could not parse date:'" + dateString + "'. Date format is dd-MM-yyyy (ex: 31-12-2011).", e); } }
From source file:Main.java
public static int getGapDay(Date startDate, Date endDate) { Calendar fromCalendar = Calendar.getInstance(); fromCalendar.setTime(startDate); fromCalendar.set(Calendar.HOUR_OF_DAY, 0); fromCalendar.set(Calendar.MINUTE, 0); fromCalendar.set(Calendar.SECOND, 0); fromCalendar.set(Calendar.MILLISECOND, 0); Calendar toCalendar = Calendar.getInstance(); toCalendar.setTime(endDate);// w w w . ja v a 2 s . c o m toCalendar.set(Calendar.HOUR_OF_DAY, 0); toCalendar.set(Calendar.MINUTE, 0); toCalendar.set(Calendar.SECOND, 0); toCalendar.set(Calendar.MILLISECOND, 0); return (int) ((toCalendar.getTime().getTime() - fromCalendar.getTime().getTime()) / (1000 * 60 * 60 * 24)); }
From source file:Main.java
public static Date getFinanacialDate(Date taxdate) { Calendar calendar = Calendar.getInstance(); calendar.setTime(taxdate); int yr = calendar.get(Calendar.YEAR); calendar.set(yr, 00, 01);/*from w ww.j av a2 s .c o m*/ taxdate = calendar.getTime(); return taxdate; }
From source file:Main.java
public static Calendar getFinishDate(String startDate, String duration) { try {/* w w w . j a v a 2 s. c o m*/ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); Calendar calendarFinish = Calendar.getInstance(); calendarFinish.setTime(sdf.parse(startDate)); calendarFinish.add(Calendar.DATE, Integer.parseInt(duration)); return calendarFinish; } catch (ParseException e) { Log.e("PARSE_FAIL", Log.getStackTraceString(e)); } return null; }
From source file:com.metamug.mtg.s3.uploader.S3Uploader.java
public static String upload(InputStream inputStream, long fileSize, String URI) { String publicURL;/*from www . java 2s . c o m*/ //ClientConfiguration max retry ObjectMetadata objectMetaData = new ObjectMetadata(); objectMetaData.setContentLength(fileSize); // objectMetaData.setContentType(IMAGE_CONTENT_TYPE); objectMetaData.setCacheControl("public"); Calendar c = Calendar.getInstance(); c.setTime(c.getTime()); c.add(Calendar.MONTH, 6); String sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss zzz").format(c.getTime()); objectMetaData.setHeader("Expires", sdf);//Thu, 21 Mar 2042 08:16:32 GMT PutObjectResult por = s3Client .putObject(new PutObjectRequest(AWS_S3_BUCKET, URI, inputStream, objectMetaData) .withCannedAcl(CannedAccessControlList.PublicRead)); publicURL = "http://metamug.net/" + URI; return publicURL; }
From source file:Main.java
public static int getGapCount(Date startDate, Date endDate) { Calendar fromCalendar = Calendar.getInstance(); fromCalendar.setTime(startDate); fromCalendar.set(Calendar.HOUR_OF_DAY, 0); fromCalendar.set(Calendar.MINUTE, 0); fromCalendar.set(Calendar.SECOND, 0); fromCalendar.set(Calendar.MILLISECOND, 0); Calendar toCalendar = Calendar.getInstance(); toCalendar.setTime(endDate);/*from www . ja v a 2s. co m*/ toCalendar.set(Calendar.HOUR_OF_DAY, 0); toCalendar.set(Calendar.MINUTE, 0); toCalendar.set(Calendar.SECOND, 0); toCalendar.set(Calendar.MILLISECOND, 0); return (int) ((toCalendar.getTime().getTime() - fromCalendar.getTime().getTime()) / (1000 * 60 * 60 * 24)); }
From source file:Main.java
public static int monthsBetweenDates(String start, String end) throws ParseException { SimpleDateFormat format = new SimpleDateFormat("MMMM, yyyy", Locale.getDefault()); Date startDate = format.parse(start); Date endDate = format.parse(end); Calendar startCalendar = new GregorianCalendar(); startCalendar.setTime(startDate); Calendar endCalendar = new GregorianCalendar(); endCalendar.setTime(endDate);/*from w ww. jav a 2 s .c om*/ int diffYear = endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR); return diffYear * 12 + endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH); }