web stats
Getting the current Datetime in javascript - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-07-2011, 12:10 AM
StefanScholte StefanScholte is offline
 
Join Date: May 2009
Location: Netherlands, Harderwijk
Posts: 321
StefanScholte is on a distinguished road
Default 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 at 05:30 AM.
Reply With Quote
  #2  
Old 02-09-2011, 06:04 AM
mourisj mourisj is offline
Mirth Guru
 
Join Date: Feb 2007
Location: Luxembourg
Posts: 407
mourisj is an unknown quantity at this point
Default

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
Reply With Quote
  #3  
Old 02-10-2011, 05:18 AM
StefanScholte StefanScholte is offline
 
Join Date: May 2009
Location: Netherlands, Harderwijk
Posts: 321
StefanScholte is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 02-10-2011, 08:51 AM
dans dans is offline
Mirth Employee
 
Join Date: Apr 2007
Location: Irvine, CA
Posts: 590
dans is an unknown quantity at this point
Default

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!
Reply With Quote
  #5  
Old 02-10-2011, 12:37 PM
mourisj mourisj is offline
Mirth Guru
 
Join Date: Feb 2007
Location: Luxembourg
Posts: 407
mourisj is an unknown quantity at this point
Default

Quote:
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
Reply With Quote
  #6  
Old 02-11-2011, 07:06 AM
StefanScholte StefanScholte is offline
 
Join Date: May 2009
Location: Netherlands, Harderwijk
Posts: 321
StefanScholte is on a distinguished road
Default

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 at 07:11 AM.
Reply With Quote
  #7  
Old 02-11-2011, 11:16 AM
dans dans is offline
Mirth Employee
 
Join Date: Apr 2007
Location: Irvine, CA
Posts: 590
dans is an unknown quantity at this point
Default

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!
Reply With Quote
  #8  
Old 02-21-2011, 11:28 AM
StefanScholte StefanScholte is offline
 
Join Date: May 2009
Location: Netherlands, Harderwijk
Posts: 321
StefanScholte is on a distinguished road
Default

Thanks a lot Daniel.

those are indeed very useful utilities.
Reply With Quote
  #9  
Old 04-08-2019, 01:04 PM
lbittle lbittle is offline
Mirth Newb
 
Join Date: Sep 2018
Posts: 21
lbittle is on a distinguished road
Default

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.
Reply With Quote
Reply

Tags
date, datetime, formatting, java

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 12:59 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation