gregorian-calendar

Organise number of days into separate sections for year, months, days, hours. Java

帅比萌擦擦* 提交于 2019-12-02 07:20:54
is there a way of organising a number of days calculated by working out the difference between two dates, into different sections e.g. for 364 days it would be: 0 years, 11 months, 30 days, hours, minutes etc. I thought using logical operators may work like % and / but as different months have different amounts of days and some years are leap years i'm not sure how to do it. Any help would be much appreciated. My code: import java.util.*; public class CleanDate { public static void main(String[] args) { Calendar cDate = GregorianCalendar.getInstance(); cDate.set(2011, 0, 31, 00, 00, 00); Date

Java Calendar Setting Incorrectly

帅比萌擦擦* 提交于 2019-12-02 05:48:22
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 == 2010 tmpMonth == 12 tmpDay == 30 tmpTime == 15 (This is the hour of the day) tmpSeconds == 0 But when

How do you convert 2 dates one in BST(Current date) and the other in GMT so that the can be compared date before and after methods?

爱⌒轻易说出口 提交于 2019-12-02 02:29:27
How do you convert 2 dates one in BST(Current date) and the other in GMT so that they can be compared using the calendar date before() and after() methods? I don't know if BST is referring to British Summer Time. I am running on a laptop with English settings. I don't know how best to do the comparison to see if one is greater than the other or equals. I figure the timezone is the problem to me successfully using the calander date after() and before() methods. I was checking equality based on the 2 calendars. I am wanting to compare dates and have been using gregorian calendars. I have 3

how to convert dateTime type to gregorianCalendar

独自空忆成欢 提交于 2019-12-02 00:31:01
问题 I am getting time in string like this "2011-02-27T10:03:33.099-06:00" which is of xml dateTime type. I also have timezone of TimeZone type. How should I convert the dateTime to GregorianCalendar java type in that timezone. 回答1: Java has built in code to parse xml datetimes: use DatatypeConverter.parseDateTime(). that will return a Calendar in the parsed TimeZone. you can then set the Calendar TimeZone to your desired target TimeZone for whatever you need to do next. 回答2: sdf = new java.text

how to add number of days to the date given in a jtextfield with string data type

女生的网名这么多〃 提交于 2019-12-01 22:03:14
Good Day . I just wanna ask about adding days in a given date. I have a jtexfield (txtStart) and another jtexfield(txtExpiry). I need to display in txtExpiry the date after 102 days from the date in txtStart. I am using KEYRELEASED event. after i input in txtStart, the date with additional 102 days shall appear in txtExpiry. here's my code but it's still erroneous. private void txtStartKeyReleased(java.awt.event.KeyEvent evt) { // TODO add your handling code here: // set calendar to 1 Jan 2007 int a = Integer.parseInt(txtStart.getText()); Calendar calendar = new GregorianCalendar(a,a,a);

Week of Year C# Datetime

不打扰是莪最后的温柔 提交于 2019-12-01 16:13:46
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 ? KingCronus The algorithm is doing exactly what you have instructed it to do. You have the CalanderWeekRule set to FirstFourDayWeek. The

How do I convert 2010-12-15T16:26:49.841-08:00 to a GregorianCalendar in Java? [duplicate]

拥有回忆 提交于 2019-12-01 14:04:13
This question already has an answer here: Converting ISO 8601-compliant String to java.util.Date 27 answers I have a string date "2010-12-15T16:26:49.841-08:00" and I need to convert it to a GregorianCalendar in Java. How do you do this? Solution from Jesper's answer Code for the solution using joda time: DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ").withOffsetParsed(); DateTime date = formatter.parseDateTime("2010-12-15T16:26:49.841-08:00"); Unfortunately, the standard SimpleDateFormat class cannot handle ISO 8601 format very well. Specifically, it

Making a digital clock in Java

我怕爱的太早我们不能终老 提交于 2019-12-01 13:49:12
I'm making a digital clock for a project and I have four classes: DigitalTimeUI , which is the JFrame class, TitlePanel , DigitPanel , and ColonPanel , which are JPanels for the item stated. When it is finished, it should look like this: The part I am stuck on is adding the DigitPanel s to the frame in the UI class. Here's what I have in the main class right now: public class DigitalTimeUI extends JFrame { public static GregorianCalendar currentDate; final static int CLOCKWIDTH = 605; final static int CLOCKHEIGHT = 200; public static void main(String[] args) { int numOfDigits = 6; int

Making a digital clock in Java

£可爱£侵袭症+ 提交于 2019-12-01 11:14:08
问题 I'm making a digital clock for a project and I have four classes: DigitalTimeUI , which is the JFrame class, TitlePanel , DigitPanel , and ColonPanel , which are JPanels for the item stated. When it is finished, it should look like this: The part I am stuck on is adding the DigitPanel s to the frame in the UI class. Here's what I have in the main class right now: public class DigitalTimeUI extends JFrame { public static GregorianCalendar currentDate; final static int CLOCKWIDTH = 605; final

Convert date between java and .net - 2 days off

自古美人都是妖i 提交于 2019-12-01 09:32:36
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 DateTime(1970, 1, 1); var javaMillis = (dt - javaEpoch).Ticks / TimeSpan.TicksPerMillisecond; dt.ToString("MM