List of usage examples for java.util Calendar set
public final void set(int year, int month, int date, int hourOfDay, int minute)
YEAR
, MONTH
, DAY_OF_MONTH
, HOUR_OF_DAY
, and MINUTE
. From source file:Main.java
public static void main(String[] args) { int dayOfWeek = Calendar.SUNDAY; Calendar cal = new GregorianCalendar(); cal.set(2015, 0, 1, 0, 0); cal.set(Calendar.DAY_OF_WEEK, dayOfWeek); while (cal.get(Calendar.YEAR) == 2015) { System.out.println(cal.getTime()); cal.add(Calendar.DAY_OF_MONTH, 7); }//from w w w. j a v a 2 s. com }
From source file:fr.itinerennes.bundler.integration.onebusaway.GenerateStaticObaApiResults.java
public static void main(String[] args) throws IOException, GtfsException { final String url = args[0]; final String key = args[1]; final String gtfsFile = args[2]; final String out = args[3].replaceAll("/$", ""); final Map<String, String> agencyMapping = new HashMap<String, String>(); agencyMapping.put("1", "2"); final GtfsDao gtfs = GtfsUtils.load(new File(gtfsFile), agencyMapping); oba = new JsonOneBusAwayClient(new DefaultHttpClient(), url, key); gson = OneBusAwayGsonFactory.newInstance(true); final Calendar end = Calendar.getInstance(); end.set(2013, 11, 22, 0, 0); final Calendar start = Calendar.getInstance(); start.set(2013, 10, 4, 0, 0);/* w w w . j a v a 2s. c o m*/ final Calendar current = Calendar.getInstance(); current.setTime(start.getTime()); while (current.before(end) || current.equals(end)) { System.out.println(current.getTime()); for (final Stop stop : gtfs.getAllStops()) { final String stopId = stop.getId().toString(); final String dateDir = String.format("%04d/%02d/%02d", current.get(Calendar.YEAR), current.get(Calendar.MONTH) + 1, current.get(Calendar.DAY_OF_MONTH)); final String methodDir = String.format("%s/schedule-for-stop", out); final File outDir = new File(String.format("%s/%s", methodDir, dateDir)); outDir.mkdirs(); final File f = new File(outDir, String.format("%s.json", stopId)); final StopSchedule ss = oba.getScheduleForStop(stopId, current.getTime()); final String json = gson.toJson(ss); final Writer w = new PrintWriter(f); w.write(json); w.close(); } current.add(Calendar.DAY_OF_MONTH, 1); } final File outDir = new File(String.format("%s/trip-details", out)); outDir.mkdirs(); for (final Trip trip : gtfs.getAllTrips()) { final String tripId = trip.getId().toString(); final File f = new File(outDir, String.format("%s.json", tripId)); final TripSchedule ts = oba.getTripDetails(tripId); final String json = gson.toJson(ts); final Writer w = new PrintWriter(f); w.write(json); w.close(); } }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // print current time System.out.println("Current year is :" + cal.getTime()); // set the year,month and day to something else cal.set(2013, 5, 25, 04, 15); // print the result System.out.println("Altered year is :" + cal.getTime()); }
From source file:MainGeneratePicasaIniFile.java
public static void main(String[] args) { try {/*from w ww . j a va2 s.c om*/ Calendar start = Calendar.getInstance(); start.set(1899, 11, 30, 0, 0); PicasawebService myService = new PicasawebService("My Application"); myService.setUserCredentials(args[0], args[1]); // Get a list of all entries URL metafeedUrl = new URL("http://picasaweb.google.com/data/feed/api/user/" + args[0] + "?kind=album"); System.out.println("Getting Picasa Web Albums entries...\n"); UserFeed resultFeed = myService.getFeed(metafeedUrl, UserFeed.class); // resultFeed. File root = new File(args[2]); File[] albuns = root.listFiles(); int j = 0; List<GphotoEntry> entries = resultFeed.getEntries(); for (int i = 0; i < entries.size(); i++) { GphotoEntry entry = entries.get(i); String href = entry.getHtmlLink().getHref(); String name = entry.getTitle().getPlainText(); for (File album : albuns) { if (album.getName().equals(name) && !href.contains("02?")) { File picasaini = new File(album, "Picasa.ini"); if (!picasaini.exists()) { StringBuilder builder = new StringBuilder(); builder.append("\n"); builder.append("[Picasa]\n"); builder.append("name="); builder.append(name); builder.append("\n"); builder.append("location="); Collection<Extension> extensions = entry.getExtensions(); for (Extension extension : extensions) { if (extension instanceof GphotoLocation) { GphotoLocation location = (GphotoLocation) extension; if (location.getValue() != null) { builder.append(location.getValue()); } } } builder.append("\n"); builder.append("category=Folders on Disk"); builder.append("\n"); builder.append("date="); String source = name.substring(0, 10); DateFormat formater = new SimpleDateFormat("yyyy-MM-dd"); Date date = formater.parse(source); Calendar end = Calendar.getInstance(); end.setTime(date); builder.append(daysBetween(start, end)); builder.append(".000000"); builder.append("\n"); builder.append(args[0]); builder.append("_lh="); builder.append(entry.getGphotoId()); builder.append("\n"); builder.append("P2category=Folders on Disk"); builder.append("\n"); URL feedUrl = new URL("https://picasaweb.google.com/data/feed/api/user/" + args[0] + "/albumid/" + entry.getGphotoId()); AlbumFeed feed = myService.getFeed(feedUrl, AlbumFeed.class); for (GphotoEntry photo : feed.getEntries()) { builder.append("\n"); builder.append("["); builder.append(photo.getTitle().getPlainText()); builder.append("]"); builder.append("\n"); long id = Long.parseLong(photo.getGphotoId()); builder.append("IIDLIST_"); builder.append(args[0]); builder.append("_lh="); builder.append(Long.toHexString(id)); builder.append("\n"); } System.out.println(builder.toString()); IOUtils.write(builder.toString(), new FileOutputStream(picasaini)); j++; } } } } System.out.println(j); System.out.println("\nTotal Entries: " + entries.size()); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static Date getDate(int year, int month, int day) { Calendar c = Calendar.getInstance(); c.set(year, month, day, 0, 0); return c.getTime(); }
From source file:Main.java
private static Calendar getCurrentExpDate() { Calendar now = Calendar.getInstance(); now.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), 0, 0, 0); return now;//from w w w . j a v a 2s .com }
From source file:Main.java
public static long getTime(int year, int month, int day, int hourOfDay, int minute) { Calendar calendar = Calendar.getInstance(); calendar.set(year, month - 1, day, hourOfDay, minute); return calendar.getTimeInMillis(); }
From source file:Main.java
public static Calendar convertTime(String year, String month, String day, String hour, String minute) { Calendar Time = Calendar.getInstance(); Time.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day), Integer.parseInt(hour), Integer.parseInt(minute)); return Time; }
From source file:org.jfree.chart.demo.WindChartDemo1.java
private static long millisForDate(int i, int j, int k) { Calendar calendar = Calendar.getInstance(); calendar.set(k, j - 1, i, 12, 0); return calendar.getTimeInMillis(); }
From source file:Main.java
public static Date getDate(int hour, int time, int year, int month, int day) { final Calendar calendar = Calendar.getInstance(); calendar.set(year, month, day, hour, time); Date date = calendar.getTime(); return date;/*from w w w . j ava 2s . c om*/ }