gregorian-calendar

Convert from Gregorian to Julian calendar [duplicate]

巧了我就是萌 提交于 2019-12-11 09:26:48
问题 This question already has answers here : Does Java support Julian calendar? (4 answers) Closed 2 years ago . I need to create a program that reads dates from a .csv file and convert it so that 13 days are added. I already did that but somehow it does not add the following dates as wished. It also goes over 30 days, which is not supposed to happen for example 2001-12-42 . public static void main(String[] args) throws FileNotFoundException, ParseException { File fread = new File("src/daten-greg

Creating a new NSCalendar calendar

穿精又带淫゛_ 提交于 2019-12-11 01:35:23
问题 I want to be able to convert between the Gregorian and Julian calendars (note: not "julian date") using NSCalendar on the iPhone. How can I subclass NSCalendar to use the Julian calendar? I want to do this without regards for 1582 or 1752 or any given year. 回答1: While you can certainly have a go at it, but I suspect that NSCalendar is tricky to subclass. It's toll-free bridged, which complicates things; is entwined with NSLocale, which complicates things; it's initialized with identifiers

How can I convert from Gregorian Calendar to Unix Time, in Java?

帅比萌擦擦* 提交于 2019-12-08 14:56:42
问题 I am in need of a method to convert GregorianCalendar Object to Unix Time (i.e. a long). Also need a method to convert Unix Time (long) back to GregorianCalendar Object. Are there any methods out there that does this? If not, then how can I do it? Any help would be highly appreciated. Link to GregorianCalendar Class --> http://download.oracle.com/javase/1.4.2/docs/api/java/util/GregorianCalendar.html Thanks. 回答1: The methods getTimeInMillis() and setTimeInMillis(long) will let you get and set

Unsure what get(Calendar.DAY_OF_WEEK) returns

风流意气都作罢 提交于 2019-12-06 11:20:10
My problem can be easily created by the scenario below: //create a gregorian calendar object that set the date and time as 4th June 2012 at 10:30PM Calendar calendar = new GregorianCalendar(2012, 6, 4, 22, 30); //when I print out these: System.out.println(calendar.get(Calendar.DAY_OF_WEEK)); System.out.println(calendar.get(Calendar.MINUTE)); System.out.println(calendar.get(Calendar.HOUR)); System.out.println(calendar.get(Calendar.DATE)); System.out.println(calendar.get(Calendar.MONTH)); System.out.println(calendar.get(Calendar.YEAR)); //output reads as: 4 30 10 4 6 2012 //so does calendar.get

How to compare XMLGregorianCalendar with only the Date portion (day, month, year)?

我与影子孤独终老i 提交于 2019-12-05 21:48:54
I'm developing a webservice integrated with spring-struts web application, in XSD there is a XMLGregorianCalendar type property, let's say the property name is trxDate . In SOAPUI testing application, if I inserted the value of trxDate with: 2013-02-21 , then I sent the soap xml request data and I printed the value in service method with: System.out.println(trxDate) method, the printout result is same as inputted: 2013-02-21. Now, I'm trying to create a function to compare trxDate with current date. I know we can compare it using trxDate.compare(currentDate) method. The problem is I don't how

Getting current Year and Month resulting strange results

半腔热情 提交于 2019-12-05 12:05:53
问题 I am working on a learning project related to Android. I am trying to get current year & month by using below code but it not works for me. GregorianCalendar gc = new GregorianCalendar(); gc.YEAR // returning 1 gc.MONTH // returning 2 Calendar c = Calendar.getInstance(); c.YEAR // returning 1 c.MONTH // returning 2 Can someone help me? Am i doing something wrong? please forgive me i am new to java development. thanks. 回答1: Just to give a bit more background: Both new GregorianCalendar() and

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

自古美人都是妖i 提交于 2019-12-05 00:51:51
问题 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! 回答1: NSDate just represents a point in time and has no format in itself. To format an NSDate to e.g. a string,

convert XMLGregorianCalendar to java.sql.Timestamp

这一生的挚爱 提交于 2019-12-04 17:27:08
问题 I'm trying to assign a XMLGregorianCalendar date to a java.sql.Timestamp var, like this... var1.setTimeStamp(Timestamp.valueOf(var2.getXMLGregorianCalendar().toString())) But apparently, this is not working, and throws an exception... java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff] And I've tried this, as well: var1.setTimeStamp((Timestamp) var2.getXMLGregorianCalendar().getTime()) but... java.lang.ClassCastException: java.util.Date cannot be cast

Convert Julian Date to Gregorian Date

♀尐吖头ヾ 提交于 2019-12-04 08:18:51
I'm writing an application in Lua that calculates the sunset/sunrise, and to do this I had to convert the Gregorian date in to Julian days initially and do all the complex maths and such from there. I've completed the hard maths, but now I need to convert the Julian date (2456495.6833865 as an example) back to a Gregorian one, complete with the time. The only code I've found that can do this only has the day, year and month, but no mention of the time (which I believe is expressed as a fraction of the day, in this case the numbers after the decimal point) Any help would be greatly appreciated

Week of Year C# Datetime

坚强是说给别人听的谎言 提交于 2019-12-04 03:11:08
问题 I have following code to get the weeknumber of the year given in the DateTime object Time public static int WeeksInYear(DateTime date) { GregorianCalendar cal = new GregorianCalendar(GregorianCalendarTypes.Localized); return cal.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday); } Now i give the function the date 1/1/2012 wich should return week 1 , but hes returning week 52. And i can't seem to figure out why. Anyone have an idea why ? 回答1: The algorithm is doing