All I must do for this code is display the current year, month and day of the year using the GregorianCalendar class. for some reason everything is right but the month. The program returns the month as being 11 instead of 12. Any suggestions?  /**  * @param args the command line arguments  */ public static void main(String[] args) {     GregorianCalendar Calendar = new GregorianCalendar();     int year = Calendar.get (GregorianCalendar.YEAR);     int month = Calendar.get (GregorianCalendar.MONTH);     int day = Calendar.get (GregorianCalendar.DAY_OF_MONTH);      System.out.println("the current year is " + year);     System.out.println("the current month is " + month);     System.out.println("the current day is " + day); }
5931
In java.util.Calendar, January is defined as month 0, not month 1. Is there any specific reason to that ?  I have seen many people getting confused about that...
33452
In a shell script, I'm processing, some addition process will print an output. If it is a single-digit one, then it has to add zero as a prefix. Here is my current script: c_year=2020 for i in {01..11}         do               n_year=2020             echo 'Next Year:'$n_year             if [[ $i == 11 ]]             then n_month=12             echo 'Next Month:'$n_month             else              n_month=$(($i + 1))             echo 'Next Month:'$n_month             fi             echo $date&quot; : Processing data '$c_year-$i-01 00:00:00' and '$n_year-$n_month-01 00:00:00'&quot;         done  The i value is in doule digit, but the n_month is still printing single digit. How do I set default shell output should return as double digit? Or any alternate way to solve this?
97059
How is it that Java's BigDecimal can be this painful?  Double d = 13.3D;  BigDecimal bd1 = new BigDecimal(d); BigDecimal bd2 = new BigDecimal(String.valueOf(d));   System.out.println("RESULT 1: "+bd1.toString()); System.out.println("RESULT 2: "+bd2.toString());  RESULT 1: 13.300000000000000710542735760100185871124267578125 RESULT 2: 13.3   Is there any situation where Result 1 would be desired? I know that Java 1.5 changed the toString() method but was this the intended consequence?   Also I realise that BigDecimal has doubleValue() etc, but the library that I am working with helpfully uses a toString() and I can't change that :-(  Cheers.
25978
Presently the date is showing as mmm dd hh:mm:ss. Is there any way that I can change it to as per my liking. For example : dd mmm, hh:mm:ss.
44986
I have a String representation of a date that I need to create a Date or Calendar object from. I've looked through Date and Calendar APIs but haven't found anything that can do this other than creating my own ugly parse method. I know there must be a way, does anyone know of a solution?
16499
If yes, on which operating system, shell or whatever?  Consider the following java program (I'm using java just as an example, any language would be good for this question, which is more about operation systems):  public class ExitCode {     public static void main(String args[]) {         System.exit(Integer.parseInt(args[0]));     } }   Running it on Linux and bash, it returns always values less equal 255, e.g. (echo $? prints the exit code of the previous executed command)  &gt; java ExitCode 2; echo $? 2  &gt; java ExitCode 128; echo $? 128  &gt; java ExitCode 255; echo $? 255  &gt; java ExitCode 256; echo $? 0  &gt; java ExitCode 65536; echo $? 0     EDITED: the (only, so far) answer below fully  explain what happens on UNIXes. I'm still wondering about other OSes.
122501
The following code returns the time of the current date:  System.debug('Current date: ' + Date.today().toStartOfMonth());   Output:     2018-08-01 00:00:00   How to remove time from date?
26496
I want to display dates in the format: short day of week, short month, day of month without leading zero but including "th", "st", "nd", or "rd" suffix.  For example, the day this question was asked would display "Thu Oct 2nd".  I'm using Ruby 1.8.7, and  just doesn't seem to do this.  I'd prefer a standard library if one exists.
89920
I've had nothing but good luck from SO, so why not try again?  I have an application that needs to show a different image based on the season of the year (spring, summer, winter, fall).   I have very specific start and end dates for these seasons.  What I would like from you geniuses is a method called GetSeason that takes a date as input and returns a String value of Spring, Summer, Winter or Fall.   Here are the date ranges and their associated seasons:  Spring:3/1-4/30 Summer:5/1-8/31 Fall:9/1-10/31 Winter: 11/1-2/28  Can someone provide a working method to return the proper season? Thanks everyone!
60964
I am running a Tomcat application, and I need to display some time values.  Unfortunately, the time is coming up an hour off.  I looked into it and discovered that my default TimeZone is being set to:  sun.util.calendar.ZoneInfo[id="GMT-08:00",                            offset=-28800000,                            dstSavings=0,                            useDaylight=false,                            transitions=0,                            lastRule=null]   Rather than the Pacific time zone.  This is further indicated when I try to print the default time zone's , and it comes up "GMT-08:00", which seems to indicate to me that it is not correctly set to the US Pacific time zone.  I am running on Ubuntu Hardy Heron, upgraded from Gutsy Gibbon.  Is there a configuration file I can update to tell the JRE to use Pacific with all the associated daylight savings time information?  The time on my machine shows correctly, so it doesn't seem to be an OS-wide misconfiguration.    Ok, here's an update. A coworker suggested I update JAVA_OPTS in my /etc/profile to include "-Duser.timezone=US/Pacific", which worked (I also saw CATALINA_OPTS, which I updated as well). Actually, I just exported the change into the variables rather than use the new /etc/profile (a reboot later will pick up the changes and I will be golden).  However, I still think there is a better solution... there should be a configuration for Java somewhere that says what timezone it is using, or how it is grabbing the timezone. If someone knows such a setting, that would be awesome, but for now this is a decent workaround.    I am using 1.5, and it is most definitely a DST problem.  As you can see, the time zone is set to not use daylight savings.  My belief is it is generically set to -8 offset rather than the specific Pacific timezone.  Since the generic -8 offset has no daylight savings info, it's of course not using it, but the question is, where do I tell Java to use Pacific time zone when it starts up?  I'm NOT looking for a programmatic solution, it should be a configuration solution.
5995
When displaying the value of a decimal currently with .ToString(), it's accurate to like 15 decimal places, and since I'm using it to represent dollars and cents, I only want the output to be 2 decimal places.   Do I use a variation of .ToString() for this?
106040
I've been using Javascript's Date for a project, but noticed today that my code that previously worked is no longer working correctly. Instead of producing Feb as expected, the code below produces March.   My code looks something like this:   current = new Date(); current.setMonth(current.getMonth()+1); //If today is Jan, expect it to be Feb now   This code worked everyday up until today. Is this a Javascript bug or am I going about this the wrong way?
7653
public class doublePrecision {     public static void main(String[] args) {          double total = 0;         total += 5.6;         total += 5.8;         System.out.println(total);     } }   The above code prints:  11.399999999999   How would I get this to just print (or be able to use it as) 11.4?
13332
I am trying to use a  as input and then creating a query with it - so I need a .    I was surprised to find that it couldn't do the conversion implicitly or explicitly - but I don't even know how I would do this, as the Java API is still fairly new to me.
5691
Is there a better way of getting this result? This function fails if num has more digits than digits, and I feel like it should be in the library somewhere (like Integer.toString(x,"%3d") or something)  static String intToString(int num, int digits) {     StringBuffer s = new StringBuffer(digits);     int zeroes = digits - (int) (Math.log(num) / Math.log(10)) - 1;      for (int i = 0; i &lt; zeroes; i++) {         s.append(0);     }     return s.append(num).toString(); }
99745
Is there a way to display previous and current year with dynamic text?    If so, what is the formatting?   I'm using ArcMap 10.0
81270
I'd like to be able to print text that varies depending on whether the date matches a given date string  For example  suppose there was a command   \iftoday#1#2#3   which printed #2 if \today matched the string in #1 and #3 otherwise.  So a sample of my proposed usage would be:     \iftoday{February 3, 2016}{There's no garbage today}{Please put out the garbage}    I've tried various commands like pdftexcmd's strcmp, to no avail.    I suspect the problem may have to do with matching the string generated by \today.    While on screen it appears that \today returns February 3, 2016. I can't get it to match February 3, 2016 when I compare strings.  Obviously, I'd be perfectly happy if I could get this to work by represent today's date in any of the standard date formats.  Thanks very much in advance for any suggestions.