Announcement

Collapse
No announcement yet.

Getting the current Datetime in javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting the current Datetime in javascript

    Hi Everyone,

    I don't know if this forum is the right place to put this.

    Sometime you will need the current date time
    in javascript this is a real pain.

    I mean you can get it very easy like this:

    Code:
    var d = new Date();
    logger.info(d.toString());
    but the result will look like this:

    Mon Feb 07 2011 09:01:17 GMT+0100 (CET)

    So I wrote a code template that gives a HL7Compliant DateTime.
    I thought lets share it.

    Code:
    //Gets the current Date Time in the format yyyyMMddHHmmss
    function GetCurrentHL7DateTime() {
    
    	var dateFormat = new Packages.java.text.SimpleDateFormat("yyyyMMddHHmmss");
    	var dateNow = new Packages.java.util.Date();
    	return dateFormat.format(dateNow).toString() + "";
    
    }
    output: 20110207081647

    As you can see I'm actually calling Java functions to do the job.
    Also I put + "" behind the return value this is to transform the java.lang.string to an javascript string.
    Last edited by StefanScholte; 02-07-2011, 04:30 AM.
    Stefan

    Mirth Certified|Epic Bridges Certified|Cloverleaf Level 2 Certified

  • #2
    I use the following code:

    // Get current date with formatting

    var curdate = DateUtil.getCurrentDate('yyyyMMddhhmm');

    //Formatting options
    // yyyy year (four-digit)
    // M, MM month, month with leading 0
    // d, dd day, day with leading 0
    // HH hour, 24-hour-format
    // hh hour, 12-hour-format
    // mm minutes
    // ss seconds
    // SSS milliseconds
    // ww week in year
    JJ Mouris
    FFE Luxembourg
    IT-Department

    Comment


    • #3
      Hi mourisj,

      That's indeed a far more better option.

      Thanks for the reply.

      You know there should be a place on the MirthCorp website where we can put these kind of scriplets so everyone can benefit from it.
      Don't you think?

      Or is there a place and did I completly missed it
      Stefan

      Mirth Certified|Epic Bridges Certified|Cloverleaf Level 2 Certified

      Comment


      • #4
        the date function JJ mentioned is available in the reference function list within Mirth Connect. You should be able to drag and drop the function to your transformer code:
        http://www.mirthcorp.com/community/w...(Transformers))
        Daniel Svanstedt
        Software Engineer
        Mirth Corporation

        Want professional services, support, and enterprise or virtual appliances? It's all available from the Mirth Corporation:
        Mirth Support | Mirth Training | Mirth Appliances | Online Training | Developer Q&A

        Don't forget, Mirth Support gives you access to all of our online training videos, and silver support gives you access to developer Q&As!

        Comment


        • #5
          Originally posted by StefanScholte View Post
          Hi mourisj,
          You know there should be a place on the MirthCorp website where we can put these kind of scriplets so everyone can benefit from it.
          Don't you think?

          Or is there a place and did I completly missed it
          I started documenting functionalities or tricks I used in Mirth ... inside a Mirth-Channel (which, of course, would do nothing but keep my documentation in the same environment where they usually are used)

          But as most of time, doing the required work takes so much time there is not enough time left for creating this kind of documentation.

          I don't know a repository on this site where you could find this kind of information. There are lots of pieces of code on this forum that could be helpful to others.
          JJ Mouris
          FFE Luxembourg
          IT-Department

          Comment


          • #6
            Well Mourisj,


            If you have some nice tips and tricks and you are willing to share them. I would be glad to receive them.
            Last edited by StefanScholte; 02-11-2011, 06:11 AM.
            Stefan

            Mirth Certified|Epic Bridges Certified|Cloverleaf Level 2 Certified

            Comment


            • #7
              Apache commons library has a lot of useful utilities. I use IOUtils and StrinEscapeUtils a lot:
              http://commons.apache.org/lang/api-2...capeUtils.html
              http://commons.apache.org/io/api-1.2...o/IOUtils.html
              Daniel Svanstedt
              Software Engineer
              Mirth Corporation

              Want professional services, support, and enterprise or virtual appliances? It's all available from the Mirth Corporation:
              Mirth Support | Mirth Training | Mirth Appliances | Online Training | Developer Q&A

              Don't forget, Mirth Support gives you access to all of our online training videos, and silver support gives you access to developer Q&As!

              Comment


              • #8
                Thanks a lot Daniel.

                those are indeed very useful utilities.
                Stefan

                Mirth Certified|Epic Bridges Certified|Cloverleaf Level 2 Certified

                Comment


                • #9
                  Posted a Mirth Minute Helper video on youtube for Date Functions, hope it helps.

                  Please subscribe to our channel:

                  https://youtu.be/BH0kIcRKAPs

                  Or, go to the Mirth Connect User Group website:

                  https://www.mcug.org in the Help Center section of the site.

                  Nextgen also has some details on this topic:

                  http://www.mirthcorp.com/community/w...ing+with+Dates

                  Good idea on code snippets, going to try to get that enabled on the Mirth Connect User Group website.

                  Comment

                  Working...
                  X