Posts

Showing posts with the label Date

In Java, Comparing And Sorting Gregorian Calendar

Image
Download

In Cpp, Calculate Easter Day And Month For Given Year

Image
#include<iostream> #include<string> using namespace std; void easter(int, int&, int &); string month(int); int main(){ int em, ed, year; cout << "What's the year: "; cin >> year; easter(year, em, ed); cout << "Easter Month is " << month(em) << endl; cout << "Easter Day is " << ed << endl; return 0; } void easter(int year, int& em, int &ed){ int a = year % 19; int b = year / 100; int c = year % 100; int d = b / 4; int e = b % 4; int f = (b + 8) / 25; int g = (b - f + 1) / 3; int h = ((19 * a) + b - d - g + 15) % 30; int i = c / 4; int j = c % 4; int k = (32 + (2 * e) + (2 * i) - h - j) % 7; int m = (a + (11 * h) + (22 * k) ) / 451; em = ( h + k - (7 * m) + 114 ) / 31; int p = ( h + k - (7 * m) + 114 ) % 31; ed = p + 1; } string month(int m){ string txt[]={"January","...

How to add days to date in Java?

Image
import java.util.Date; import java.util.Calendar; import java.text.DateFormat; import java.text.SimpleDateFormat; public class Test{ public static void main(String[]args){ final Date[]dates=new Date[7]; Calendar cal = Calendar.getInstance(); DateFormat fmt = new SimpleDateFormat("dd-MMM-yyyy"); cal.set(Calendar.MONTH, 2); cal.set(Calendar.YEAR, 2021); for(byte day = 26, i = 0; dates.length > i; day++, i++){ cal.set(Calendar.DAY_OF_MONTH, day); dates[i] = cal.getTime(); } for(Date dt : dates){ System.out.println(fmt.format(dt)); } } } Download

Transform/Convert date string yyyy/mm/dd to dd-mm-yyyy | Java Date String

Image
Download code here .

Take notes and auto insert current date time of notes | Windows Notepad ...

Image

JavaScript get Day of Week for next X years

Image
Download code here .