List of usage examples for java.util Calendar YEAR
int YEAR
To view the source code for java.util Calendar YEAR.
Click Source Link
get
and set
indicating the year. From source file:TextVerifyInputFormatDate.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout()); final Text text = new Text(shell, SWT.BORDER); text.setText("YYYY/MM/DD"); ;/*ww w. j av a 2s. c om*/ final Calendar calendar = Calendar.getInstance(); text.addListener(SWT.Verify, new Listener() { boolean ignore; public void handleEvent(Event e) { if (ignore) return; e.doit = false; StringBuffer buffer = new StringBuffer(e.text); char[] chars = new char[buffer.length()]; buffer.getChars(0, chars.length, chars, 0); if (e.character == '\b') { for (int i = e.start; i < e.end; i++) { switch (i) { case 0: /* [Y]YYY */ case 1: /* Y[Y]YY */ case 2: /* YY[Y]Y */ case 3: /* YYY[Y] */ { buffer.append('Y'); break; } case 5: /* [M]M */ case 6: /* M[M] */ { buffer.append('M'); break; } case 8: /* [D]D */ case 9: /* D[D] */ { buffer.append('D'); break; } case 4: /* YYYY[/]MM */ case 7: /* MM[/]DD */ { buffer.append('/'); break; } default: return; } } text.setSelection(e.start, e.start + buffer.length()); ignore = true; text.insert(buffer.toString()); ignore = false; text.setSelection(e.start, e.start); return; } int start = e.start; if (start > 9) return; int index = 0; for (int i = 0; i < chars.length; i++) { if (start + index == 4 || start + index == 7) { if (chars[i] == '/') { index++; continue; } buffer.insert(index++, '/'); } if (chars[i] < '0' || '9' < chars[i]) return; if (start + index == 5 && '1' < chars[i]) return; /* [M]M */ if (start + index == 8 && '3' < chars[i]) return; /* [D]D */ index++; } String newText = buffer.toString(); int length = newText.length(); StringBuffer date = new StringBuffer(text.getText()); date.replace(e.start, e.start + length, newText); calendar.set(Calendar.YEAR, 1901); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DATE, 1); String yyyy = date.substring(0, 4); if (yyyy.indexOf('Y') == -1) { int year = Integer.parseInt(yyyy); calendar.set(Calendar.YEAR, year); } String mm = date.substring(5, 7); if (mm.indexOf('M') == -1) { int month = Integer.parseInt(mm) - 1; int maxMonth = calendar.getActualMaximum(Calendar.MONTH); if (0 > month || month > maxMonth) return; calendar.set(Calendar.MONTH, month); } String dd = date.substring(8, 10); if (dd.indexOf('D') == -1) { int day = Integer.parseInt(dd); int maxDay = calendar.getActualMaximum(Calendar.DATE); if (1 > day || day > maxDay) return; calendar.set(Calendar.DATE, day); } else { if (calendar.get(Calendar.MONTH) == Calendar.FEBRUARY) { char firstChar = date.charAt(8); if (firstChar != 'D' && '2' < firstChar) return; } } text.setSelection(e.start, e.start + length); ignore = true; text.insert(newText); ignore = false; } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:com.microsoft.windowsazure.services.media.samples.contentprotection.playreadywidevine.Program.java
public static void main(String[] args) { try {//from w ww . jav a2 s. co m // Set up the MediaContract object to call into the Media Services account Configuration configuration = MediaConfiguration.configureWithOAuthAuthentication(mediaServiceUri, oAuthUri, clientId, clientSecret, scope); mediaService = MediaService.create(configuration); System.out.println("Azure SDK for Java - PlayReady & Widevine Dynamic Encryption Sample"); // Upload a local file to a media asset. AssetInfo uploadAsset = uploadFileAndCreateAsset("Azure-Video.wmv"); System.out.println("Uploaded Asset Id: " + uploadAsset.getId()); // Transform the asset. AssetInfo encodedAsset = encode(uploadAsset); System.out.println("Encoded Asset Id: " + encodedAsset.getId()); // Create the ContentKey ContentKeyInfo contentKeyInfo = createCommonTypeContentKey(encodedAsset); System.out.println("Common Encryption Content Key: " + contentKeyInfo.getId()); // Create the ContentKeyAuthorizationPolicy String tokenTemplateString = null; if (tokenRestriction) { tokenTemplateString = addTokenRestrictedAuthorizationPolicy(contentKeyInfo, tokenType); } else { addOpenAuthorizationPolicy(contentKeyInfo); } // Create the AssetDeliveryPolicy createAssetDeliveryPolicy(encodedAsset, contentKeyInfo); if (tokenTemplateString != null) { // Deserializes a string containing the XML representation of the TokenRestrictionTemplate TokenRestrictionTemplate tokenTemplate = TokenRestrictionTemplateSerializer .deserialize(tokenTemplateString); // Generate a test token based on the the data in the given // TokenRestrictionTemplate. // Note: You need to pass the key id Guid because we specified // TokenClaim.ContentKeyIdentifierClaim in during the creation // of TokenRestrictionTemplate. UUID rawKey = UUID.fromString(contentKeyInfo.getId().substring("nb:kid:UUID:".length())); // Token expiration: 1-year Calendar date = Calendar.getInstance(); date.setTime(new Date()); date.add(Calendar.YEAR, 1); // Generate token String testToken = TokenRestrictionTemplateSerializer.generateTestToken(tokenTemplate, null, rawKey, date.getTime(), null); System.out.println(tokenTemplate.getTokenType().toString() + " Test Token: Bearer " + testToken); } // Create the Streaming Origin Locator String url = getStreamingOriginLocator(encodedAsset); System.out.println("Origin Locator Url: " + url); System.out.println("Sample completed!"); } catch (ServiceException se) { System.out.println("ServiceException encountered."); System.out.println(se.toString()); } catch (Exception e) { System.out.println("Exception encountered."); System.out.println(e.toString()); } }
From source file:se.technipelago.weather.chart.Generator.java
public static void main(String[] args) { Generator generator = new Generator(); if (args.length > 0) { String outputDir = args[0]; if (outputDir.endsWith("/")) { outputDir = outputDir.substring(0, outputDir.length() - 1); }/*from www. j a v a 2 s . c om*/ generator.setOutputDirectory(outputDir); } // Generate charts. generator.init(); Map<String, Object> data = generator.getWeatherData(); generator.generateCurrentCharts(data); generator.generateHistoryCharts(-30, 31); int year = Calendar.getInstance().get(Calendar.YEAR); generator.generateMonthlyCharts(year); generator.generateYearlyCharts(year); }
From source file:Main.java
public static int getYear() { return getTimeByType(Calendar.YEAR); }
From source file:Main.java
public static int getYear() { return Calendar.getInstance().get(Calendar.YEAR); }
From source file:Main.java
public static int getYear(Calendar calendar) { return calendar.get(Calendar.YEAR); }
From source file:Main.java
public static int getCurYear() { return Calendar.getInstance().get(Calendar.YEAR); }
From source file:Main.java
public static String calendar2str(Calendar c) { int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH) + 1; int day = c.get(Calendar.DAY_OF_MONTH); return year + "-" + month + "-" + day; }
From source file:Main.java
public static int getCurrentYear() { return Calendar.getInstance().get(Calendar.YEAR); }
From source file:Main.java
public static String formatNoaaForCalendar(Calendar c) { return "" + c.get(Calendar.YEAR) + "-" + String.format("%02d", (c.get(Calendar.MONTH) + 1)) + "-" + String.format("%02d", c.get(Calendar.DATE)); }