Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Java Rant

Java Rant

Scheduled Pinned Locked Moved The Lounge
questioncsharpjavaannouncement
19 Posts 13 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Nu Er Ha Chi

    I haven't used Java for a while. My company is moving from .NET to Java, so I downloaded the most recent version of J2SE (5.0). I hate it already. How do I build a string as time stamp based on the current time? The format I want is: yyyyMMddHHmmss (i.e. year, month, day, hour, minute, second) With .NET, I need only to do this: string sTimestamp = DateTime.Now.ToString("yyyyMMddHHmmss"); Here is what I have to do in Java: GregorianCalendar oCal = new GregorianCalendar(); int nYear = oCal.get(Calendar.YEAR); int nMonth = oCal.get(Calendar.MONTH); int nDay = oCal.get(Calendar.DAY_OF_MONTH); int nAMPM = oCal.get(Calendar.AM_PM); int nHour = nAMPM>0?(oCal.get(Calendar.HOUR)+12):oCal.get(Calendar.HOUR); int nMinute = oCal.get(Calendar.MINUTE); int nSecond = oCal.get(Calendar.SECOND); String sTimestamp = new Integer(nYear).toString()+ (nMonth<9?("0"+new Integer(nMonth+1).toString()):new Integer(nMonth+1).toString())+ (nDay<10?("0"+new Integer(nDay).toString()):new Integer(nDay).toString())+ (nHour<10?("0"+new Integer(nHour).toString()):new Integer(nHour).toString())+ (nMinute<10?("0"+new Integer(nMinute).toString()):new Integer(nMinute).toString())+ (nSecond<10?("0"+new Integer(nSecond).toString()):new Integer(nSecond).toString()); Note that the month value returned by oCal.get(Calendar.MONTH) is 0 based, unlike all the other fields. What the ****? :mad:

    D Offline
    D Offline
    Diego Moita
    wrote on last edited by
    #5

    Nu Er Ha Chi wrote: How do I build a string as time stamp based on the current time? Er... Wouldn't this[^] work?

    N 1 Reply Last reply
    0
    • N Nu Er Ha Chi

      I haven't used Java for a while. My company is moving from .NET to Java, so I downloaded the most recent version of J2SE (5.0). I hate it already. How do I build a string as time stamp based on the current time? The format I want is: yyyyMMddHHmmss (i.e. year, month, day, hour, minute, second) With .NET, I need only to do this: string sTimestamp = DateTime.Now.ToString("yyyyMMddHHmmss"); Here is what I have to do in Java: GregorianCalendar oCal = new GregorianCalendar(); int nYear = oCal.get(Calendar.YEAR); int nMonth = oCal.get(Calendar.MONTH); int nDay = oCal.get(Calendar.DAY_OF_MONTH); int nAMPM = oCal.get(Calendar.AM_PM); int nHour = nAMPM>0?(oCal.get(Calendar.HOUR)+12):oCal.get(Calendar.HOUR); int nMinute = oCal.get(Calendar.MINUTE); int nSecond = oCal.get(Calendar.SECOND); String sTimestamp = new Integer(nYear).toString()+ (nMonth<9?("0"+new Integer(nMonth+1).toString()):new Integer(nMonth+1).toString())+ (nDay<10?("0"+new Integer(nDay).toString()):new Integer(nDay).toString())+ (nHour<10?("0"+new Integer(nHour).toString()):new Integer(nHour).toString())+ (nMinute<10?("0"+new Integer(nMinute).toString()):new Integer(nMinute).toString())+ (nSecond<10?("0"+new Integer(nSecond).toString()):new Integer(nSecond).toString()); Note that the month value returned by oCal.get(Calendar.MONTH) is 0 based, unlike all the other fields. What the ****? :mad:

      N Offline
      N Offline
      nlecren
      wrote on last edited by
      #6

      Look into SimpleDateFormat

      1 Reply Last reply
      0
      • N Nu Er Ha Chi

        I haven't used Java for a while. My company is moving from .NET to Java, so I downloaded the most recent version of J2SE (5.0). I hate it already. How do I build a string as time stamp based on the current time? The format I want is: yyyyMMddHHmmss (i.e. year, month, day, hour, minute, second) With .NET, I need only to do this: string sTimestamp = DateTime.Now.ToString("yyyyMMddHHmmss"); Here is what I have to do in Java: GregorianCalendar oCal = new GregorianCalendar(); int nYear = oCal.get(Calendar.YEAR); int nMonth = oCal.get(Calendar.MONTH); int nDay = oCal.get(Calendar.DAY_OF_MONTH); int nAMPM = oCal.get(Calendar.AM_PM); int nHour = nAMPM>0?(oCal.get(Calendar.HOUR)+12):oCal.get(Calendar.HOUR); int nMinute = oCal.get(Calendar.MINUTE); int nSecond = oCal.get(Calendar.SECOND); String sTimestamp = new Integer(nYear).toString()+ (nMonth<9?("0"+new Integer(nMonth+1).toString()):new Integer(nMonth+1).toString())+ (nDay<10?("0"+new Integer(nDay).toString()):new Integer(nDay).toString())+ (nHour<10?("0"+new Integer(nHour).toString()):new Integer(nHour).toString())+ (nMinute<10?("0"+new Integer(nMinute).toString()):new Integer(nMinute).toString())+ (nSecond<10?("0"+new Integer(nSecond).toString()):new Integer(nSecond).toString()); Note that the month value returned by oCal.get(Calendar.MONTH) is 0 based, unlike all the other fields. What the ****? :mad:

        E Offline
        E Offline
        eggie5
        wrote on last edited by
        #7

        Why are they switching to java? Is it for linux??? /\ |_ E X E GG

        1 Reply Last reply
        0
        • D Diego Moita

          Nu Er Ha Chi wrote: How do I build a string as time stamp based on the current time? Er... Wouldn't this[^] work?

          N Offline
          N Offline
          Nu Er Ha Chi
          wrote on last edited by
          #8

          Yes, it does. Thanks.

          1 Reply Last reply
          0
          • N Nu Er Ha Chi

            I haven't used Java for a while. My company is moving from .NET to Java, so I downloaded the most recent version of J2SE (5.0). I hate it already. How do I build a string as time stamp based on the current time? The format I want is: yyyyMMddHHmmss (i.e. year, month, day, hour, minute, second) With .NET, I need only to do this: string sTimestamp = DateTime.Now.ToString("yyyyMMddHHmmss"); Here is what I have to do in Java: GregorianCalendar oCal = new GregorianCalendar(); int nYear = oCal.get(Calendar.YEAR); int nMonth = oCal.get(Calendar.MONTH); int nDay = oCal.get(Calendar.DAY_OF_MONTH); int nAMPM = oCal.get(Calendar.AM_PM); int nHour = nAMPM>0?(oCal.get(Calendar.HOUR)+12):oCal.get(Calendar.HOUR); int nMinute = oCal.get(Calendar.MINUTE); int nSecond = oCal.get(Calendar.SECOND); String sTimestamp = new Integer(nYear).toString()+ (nMonth<9?("0"+new Integer(nMonth+1).toString()):new Integer(nMonth+1).toString())+ (nDay<10?("0"+new Integer(nDay).toString()):new Integer(nDay).toString())+ (nHour<10?("0"+new Integer(nHour).toString()):new Integer(nHour).toString())+ (nMinute<10?("0"+new Integer(nMinute).toString()):new Integer(nMinute).toString())+ (nSecond<10?("0"+new Integer(nSecond).toString()):new Integer(nSecond).toString()); Note that the month value returned by oCal.get(Calendar.MONTH) is 0 based, unlike all the other fields. What the ****? :mad:

            J Offline
            J Offline
            jan larsen
            wrote on last edited by
            #9

            Nu Er Ha Chi wrote: I haven't used Java for a while. And before that you didn't do much either I presume :-) "God doesn't play dice" - Albert Einstein "God not only plays dice, He sometimes throws the dices where they cannot be seen" - Niels Bohr

            1 Reply Last reply
            0
            • N Nu Er Ha Chi

              I haven't used Java for a while. My company is moving from .NET to Java, so I downloaded the most recent version of J2SE (5.0). I hate it already. How do I build a string as time stamp based on the current time? The format I want is: yyyyMMddHHmmss (i.e. year, month, day, hour, minute, second) With .NET, I need only to do this: string sTimestamp = DateTime.Now.ToString("yyyyMMddHHmmss"); Here is what I have to do in Java: GregorianCalendar oCal = new GregorianCalendar(); int nYear = oCal.get(Calendar.YEAR); int nMonth = oCal.get(Calendar.MONTH); int nDay = oCal.get(Calendar.DAY_OF_MONTH); int nAMPM = oCal.get(Calendar.AM_PM); int nHour = nAMPM>0?(oCal.get(Calendar.HOUR)+12):oCal.get(Calendar.HOUR); int nMinute = oCal.get(Calendar.MINUTE); int nSecond = oCal.get(Calendar.SECOND); String sTimestamp = new Integer(nYear).toString()+ (nMonth<9?("0"+new Integer(nMonth+1).toString()):new Integer(nMonth+1).toString())+ (nDay<10?("0"+new Integer(nDay).toString()):new Integer(nDay).toString())+ (nHour<10?("0"+new Integer(nHour).toString()):new Integer(nHour).toString())+ (nMinute<10?("0"+new Integer(nMinute).toString()):new Integer(nMinute).toString())+ (nSecond<10?("0"+new Integer(nSecond).toString()):new Integer(nSecond).toString()); Note that the month value returned by oCal.get(Calendar.MONTH) is 0 based, unlike all the other fields. What the ****? :mad:

              M Offline
              M Offline
              Marc Clifton
              wrote on last edited by
              #10

              Nu Er Ha Chi wrote: My company is moving from .NET to Java Wow. First time I ever heard someone going that direction. Seems rather backwards to me. Maybe after spending a year on Java, they'll want you to move to VB next. :-D Marc My website
              Latest Articles: Object Comparer String Helpers

              C N 2 Replies Last reply
              0
              • M Marc Clifton

                Nu Er Ha Chi wrote: My company is moving from .NET to Java Wow. First time I ever heard someone going that direction. Seems rather backwards to me. Maybe after spending a year on Java, they'll want you to move to VB next. :-D Marc My website
                Latest Articles: Object Comparer String Helpers

                C Offline
                C Offline
                code frog 0
                wrote on last edited by
                #11

                Marc Clifton wrote: Maybe after spending a year on Java, they'll want you to move to VB next. Cobol would be a better choice.

                My name is Maximus Decimus Meridius, commander of the Armies of the North, General of the Felix Legions, loyal servant to the true emperor, Marcus Aurelius. Father to a murdered son, husband to a murdered wife. And I will finish this project, in this life or the next. Slightly modified " from Gladiator. Code-frog System Architects, Inc.

                1 Reply Last reply
                0
                • M Marc Clifton

                  Nu Er Ha Chi wrote: My company is moving from .NET to Java Wow. First time I ever heard someone going that direction. Seems rather backwards to me. Maybe after spending a year on Java, they'll want you to move to VB next. :-D Marc My website
                  Latest Articles: Object Comparer String Helpers

                  N Offline
                  N Offline
                  Nemanja Trifunovic
                  wrote on last edited by
                  #12

                  Marc Clifton wrote: Seems rather backwards to me. Maybe they have customers who want their software to run on Unix.


                  My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.

                  E T 2 Replies Last reply
                  0
                  • N Nemanja Trifunovic

                    Marc Clifton wrote: Seems rather backwards to me. Maybe they have customers who want their software to run on Unix.


                    My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.

                    E Offline
                    E Offline
                    eggie5
                    wrote on last edited by
                    #13

                    TRUE. /\ |_ E X E GG

                    D 1 Reply Last reply
                    0
                    • N Nemanja Trifunovic

                      Marc Clifton wrote: Seems rather backwards to me. Maybe they have customers who want their software to run on Unix.


                      My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.

                      T Offline
                      T Offline
                      Tad McClellan
                      wrote on last edited by
                      #14

                      I think there are versions of the CLR which will run on linux.

                      D 1 Reply Last reply
                      0
                      • T Tad McClellan

                        I think there are versions of the CLR which will run on linux.

                        D Offline
                        D Offline
                        DavidNohejl
                        wrote on last edited by
                        #15

                        For example Mono. Never forget: "Stay kul and happy" (I.A.)
                        David's thoughts / dnhsoftware.org / MyHTMLTidy

                        1 Reply Last reply
                        0
                        • E eggie5

                          TRUE. /\ |_ E X E GG

                          D Offline
                          D Offline
                          DavidNohejl
                          wrote on last edited by
                          #16

                          Do you know that you can actually turn the CAPS LOCK off? Just hit it again... :rolleyes: Never forget: "Stay kul and happy" (I.A.)
                          David's thoughts / dnhsoftware.org / MyHTMLTidy

                          E 1 Reply Last reply
                          0
                          • D DavidNohejl

                            Do you know that you can actually turn the CAPS LOCK off? Just hit it again... :rolleyes: Never forget: "Stay kul and happy" (I.A.)
                            David's thoughts / dnhsoftware.org / MyHTMLTidy

                            E Offline
                            E Offline
                            eggie5
                            wrote on last edited by
                            #17

                            Are you mad at me? Why would you speak to me thusly? /\ |_ E X E GG

                            D 1 Reply Last reply
                            0
                            • E eggie5

                              Are you mad at me? Why would you speak to me thusly? /\ |_ E X E GG

                              D Offline
                              D Offline
                              DavidNohejl
                              wrote on last edited by
                              #18

                              Nothing personal, just your pleaure for uppercase letters and my averse to them, plus your great sense of humor makes you target :P Easy, Alex. ;) Never forget: "Stay kul and happy" (I.A.)
                              David's thoughts / dnhsoftware.org / MyHTMLTidy

                              E 1 Reply Last reply
                              0
                              • D DavidNohejl

                                Nothing personal, just your pleaure for uppercase letters and my averse to them, plus your great sense of humor makes you target :P Easy, Alex. ;) Never forget: "Stay kul and happy" (I.A.)
                                David's thoughts / dnhsoftware.org / MyHTMLTidy

                                E Offline
                                E Offline
                                eggie5
                                wrote on last edited by
                                #19

                                oh, alright then. /\ |_ E X E GG

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups