GoogleSearchBox

Custom Search

Wednesday, August 28, 2013

format java date from string MM/dd/yyyy HH:mm:ss a

String datetimeString = "6/7/2013 2:55:44 PM";  // A String representing your date
java.util.Date result = new Date();
DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");

// Below Will Throw Exception in thread "main" java.text.ParseException: Unparseable date:
// SimpleDateFormat formatter = new SimpleDateFormat("MM-dd-yyyy"); 

result = formatter.parse(datetimeString); // Throws ParseException
System.out.println("Parse Java Util Date  = "+result);
System.out.println("formatted: " + formatter.format(result));


Output is:
Parse Java Util Date  = Fri Jun 07 14:55:44 GMT+05:30 2013

formatted: 06/07/2013 02:55:44 PM



Refer below posts for more examples:
http://viralpatel.net/blogs/check-string-is-valid-date-java/
http://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html

Tuesday, August 20, 2013

How to pass multiple property (option) values as an argument to a method in JQuery

For an jQuery API we have multiples of options to use from for a method.
For example, for the jQuery UI Dialog widget we have a lot of options to choose from like we have maxHeight, minWidth, modal, resizable, draggable to achieve different functionalyties with the widget.

So how to use all or some of these options with the dialog method ?

Here is how we can do it:
We can create a variable containing all the options (name:value) with comma(,) in between multiple values (basically json notation) and then pass the variable to the dialog() method.

  $(function(){
 var dialogOpts = {
  show: true,
  hide: true,
  maxHeight: 400,
  minWidth: 850
 };
 $("#dialog").dialog(dialogOpts);
  });

where "dialog" is the div name inside your html's body as follows :
<div id="dialog" title="Basic dialog">

  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>

  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>

  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>

  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>

  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>

  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>

  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>

</div>




Tags:
jquery option chain
jquery ui option chaining
jquery method option chaining
How to use multiple options to pass to a method in JQuery
How to use multiple options using options for jQuery method
How to use multiple options to pass to a method in JQuery

What is the dollar Sign ($) means in JQuery Or how to avoid $ collision from jquery with other languages or technologies

$ (dollar) sign in Jquery is just a method name or identifier name.

As javascript allows the $ sign as a special character including some other special characters to be used as a valid variable name (identifier) or a valid method name.

To make it simple, jQuery and some other languages (scripting or coding) has choosen this $ to use their api (methods) easily.

In jQuery, we can replace the $ sign with the word "jQuery" whenever we encounter $ collision issues with some other coding languages like JSTL (JSP, EL) or prototype etc. and it will do the trick.
Infact we can say, $ is a shortcut symbol for the "jQuery" word.

So in jQuery below code :
<script>
  $(function() {
    $( "#dialog" ).dialog();
  });
</script>

is Same as below code:
<script>
  jQuery(function() {
    jQuery( "#dialog" ).dialog();
  });
</script>



Tags:
What is the dollar Sign ($) means in JQuery ?
How to avoid $ collision from jquery with other languages or technologies ?