gregorian-calendar

Convert date between java and .net - 2 days off

三世轮回 提交于 2019-12-04 01:54:50
问题 I need to transform a .NET DateTime to an equivalent Java Calendar representation. The .NET DateTime uses Ticks since Jan 1st 0001 (the .NET epoch) as the underlying representation. The Java GregorianCalendar uses milliseconds since Jan 1st 1970 (the Java (or Unix) epoch). The value is negative for dates before the Java epoch, as expected. Here I'm transforming the DateTime representation in millis since the Java epoch: var dt = new DateTime(1,2,3); //way, way back. var javaEpoch = new

Gregorian to Hebrew

眉间皱痕 提交于 2019-12-03 21:25:32
问题 How to convert a gregorian date into the equivalent hebrew date? Also please tell about these calendars as I am not having much knowledge of these. 回答1: There's a handy class called NSCalendar. You create one like this: NSCalendar * gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSCalendar * hebrew = [[NSCalendar alloc] initWithCalendarIdentifier:NSHebrewCalendar]; Once you've got the calendar objects, you can use them to convert a date around to various

Algorithm to find the Gregorian date of the Chinese New Year of a certain Gregorian year

江枫思渺然 提交于 2019-12-03 17:11:05
I am making a driver to calculate various holidays in a given time span. So, I need to find the Gregorian dates of all the Chinese Holidays (Chinese New Year, QingMing Festival, Dragon Boat Festival, etc). I used the famous 'Easter algorithm' for Good Friday, Easter Monday, Ascension Day, and Whit Monday calculations; however, I don't understand it well enough to adapt it for the Chinese calendar. I have found similar questions, but they often go from Gregorian to Chinese: Moon / Lunar Phase Algorithm Calculating lunar/lunisolar holidays in python http://www.herongyang.com/year/program.html

How to get today's date in the Gregorian format when phone calendar is non-Gregorian?

为君一笑 提交于 2019-12-03 16:28:41
NSDate *now = [[NSDate alloc] init]; gives the current date. However if the phone calendar is not Gregorian (on the emulator there is also Japanese and Buddhist), the current date will not be Gregorian. The question now is how to convert to a Gregorian date or make sure it will be in the Gregorian format from the beginning. This is crucial for some server communication. Thank you! NSDate just represents a point in time and has no format in itself. To format an NSDate to e.g. a string, you should use NSDateFormatter. It has a calendar property, and if you set this property to an instance of a

Getting current datetime using Calendar.getInstance() vs new GregorianCalendar()

别来无恙 提交于 2019-12-03 05:30:41
问题 What might be the difference between getting datetime using Calendar.getInstance() vs new GregorianCalendar() ? 回答1: Looking in the source of Calendar.getInstance(): private static Calendar createCalendar(TimeZone zone, Locale aLocale) { // If the specified locale is a Thai locale, returns a BuddhistCalendar // instance. if ("th".equals(aLocale.getLanguage()) && ("TH".equals(aLocale.getCountry()))) { return new sun.util.BuddhistCalendar(zone, aLocale); } else if ("JP".equals(aLocale

Getting current datetime using Calendar.getInstance() vs new GregorianCalendar()

吃可爱长大的小学妹 提交于 2019-12-02 17:52:55
What might be the difference between getting datetime using Calendar.getInstance() vs new GregorianCalendar() ? Looking in the source of Calendar.getInstance() : private static Calendar createCalendar(TimeZone zone, Locale aLocale) { // If the specified locale is a Thai locale, returns a BuddhistCalendar // instance. if ("th".equals(aLocale.getLanguage()) && ("TH".equals(aLocale.getCountry()))) { return new sun.util.BuddhistCalendar(zone, aLocale); } else if ("JP".equals(aLocale.getVariant()) && "JP".equals(aLocale.getCountry()) && "ja".equals(aLocale.getLanguage())) { return new

How to initialize Gregorian calendar with date as YYYY-MM-DD format?

佐手、 提交于 2019-12-02 15:41:09
问题 I have a class which contains a variable private GregorianCalendar cal; Now I want to initialize it with a date in yyyy-mm-dd format, I tried using the default constructor but the output I get is something like this "2017-05-25T14:36:52+03:00" , I only want "2017-05-25" date part? How do I achieve it? 回答1: First, you may hate me for reiterating, you need to understand that there’s a difference between a date and a string representation of that date; a difference between the fundamental data

Java GregorianCalendar and Calendar misplace weekends, days in a month for August and September, 2010

故事扮演 提交于 2019-12-02 15:05:15
问题 I'm trying to use either Calendar or Gregorian Calendar to iterate and create a date grid. However, both of them seem to think that August, 2010 has 30 days, and that September 2 and 3 are weekends. It's as if the calendar has the wrong year, but I've tripple-checked that parameter. Here are some excerpts. startDate.set(2010, 8, 28); SchedulerCalendar currentDate = (SchedulerCalendar) startDate.clone(); for(int i = 0; i<daysDisplayed; i++){ newDate = new TextView(this); String dateString =

Java Calendar Setting Incorrectly

不打扰是莪最后的温柔 提交于 2019-12-02 14:01:20
问题 I'm having some trouble with Java's Calendar. I'm parsing some data from a txt file, and need to create a date. After completion of the following code: tmpYear = Double.parseDouble(row[yearIndex]); tmpMonth = Double.parseDouble(row[monthIndex]); tmpDay = Double.parseDouble(row[dayIndex]); if(timeIndex != -1) tmpTime = Double.parseDouble(row[timeIndex]); if(secondsIndex != -1) tmpSeconds = Double.parseDouble(row[secondsIndex]); I can debug and see that the variables are as follows: tmpYear ==

Java GregorianCalendar and Calendar misplace weekends, days in a month for August and September, 2010

Deadly 提交于 2019-12-02 08:55:33
I'm trying to use either Calendar or Gregorian Calendar to iterate and create a date grid. However, both of them seem to think that August, 2010 has 30 days, and that September 2 and 3 are weekends. It's as if the calendar has the wrong year, but I've tripple-checked that parameter. Here are some excerpts. startDate.set(2010, 8, 28); SchedulerCalendar currentDate = (SchedulerCalendar) startDate.clone(); for(int i = 0; i<daysDisplayed; i++){ newDate = new TextView(this); String dateString = currentDate.get(Calendar.MONTH)+"/"+currentDate.get(Calendar.DATE); //+"/"+currentDate.get(Calendar.YEAR)