/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2012-2014 lacolaco.net
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package net.lacolaco.smileessence.util;

import java.util.Calendar;
import java.util.Date;

public class StringUtils
{

    // -------------------------- STATIC METHODS --------------------------

    public static String dateToString(Date date)
    {
        Calendar cal = Calendar.getInstance();
        Calendar calToday = Calendar.getInstance();

        cal.setTime(date);

        int y = cal.get(Calendar.YEAR);
        int m = cal.get(Calendar.MONTH);
        int d = cal.get(Calendar.DATE);
        int h = cal.get(Calendar.HOUR_OF_DAY);
        int min = cal.get(Calendar.MINUTE);
        int s = cal.get(Calendar.SECOND);

        StringBuilder builder = new StringBuilder();

        if(cal.get(Calendar.YEAR) != calToday.get(Calendar.YEAR))
        {
            builder.append(y).append("/");
        }
        if(cal.get(Calendar.DAY_OF_YEAR) != calToday.get(Calendar.DAY_OF_YEAR))
        {
            builder.append(String.format("%02d", m + 1)).append("/").append(String.format("%02d", d)).append(" ");
        }
        builder.append(String.format("%02d", h)).append(":").append(String.format("%02d", min)).append(":").append(String.format("%02d", s));

        return builder.toString();
    }
}

@@ -1185,16 +1185,51 @@
 .util;%0A%0A
+import java.text.SimpleDateFormat;%0A
 import j
@@ -1482,61 +1482,8 @@
 ();%0A
-        Calendar calToday = Calendar.getInstance();%0A%0A
     
@@ -1519,15 +1519,10 @@
    i
-nt y = 
+f(
 cal.
@@ -1543,70 +1543,34 @@
 EAR)
-;%0A        int m = cal.get(Calendar.MONTH);%0A        int d = cal
+ == Calendar.getInstance()
 .get
@@ -1583,14 +1583,14 @@
 dar.
-DATE);
+YEAR))
 %0A   
@@ -1598,254 +1598,112 @@
     
-int h = cal.get(Calendar.HOUR_OF_DAY);%0A        int min = cal.get(Calendar.MINUTE);%0A        int s = cal.get(Calendar.SECOND);%0A%0A        StringBuilder builder = new StringBuilder();%0A%0A        if(cal.get(Calendar.YEAR) != calToday.get(Calendar.
+%7B%0A            if(cal.get(Calendar.DAY_OF_YEAR) == Calendar.getInstance().get(Calendar.DAY_OF_
 YEAR))%0A
+    
     
@@ -1724,262 +1724,198 @@
     
-builder.append(y).append(%22/%22);%0A        %7D%0A        if(cal.get(Calendar.DAY_OF_YEAR) != calToday.get(Calendar.DAY_OF_YEAR))%0A        %7B%0A            builder.append(String.format(%22%2502d%22, m + 1)).append(%22/%22).append(String.format(%22%2502d%22, d)).append(%22 %22);%0A
+    return new SimpleDateFormat(%22hh:mm:ss%22).format(date);%0A            %7D%0A            else%0A            %7B%0A                return new SimpleDateFormat(%22MM/dd hh:mm:ss%22).format(date);%0A   
         
 %7D%0A  
@@ -1902,32 +1902,33 @@
 te);%0A           
+ 
 %7D%0A        builde
@@ -1925,151 +1925,118 @@
     
-builder.append(String.format(%22%2502d%22, h)).append(%22:%22).append(String.format(%22%2502d%22, min)).append(%22:%22).append(String.format(%22%2502d%22, s)
+%7D%0A        else%0A        %7B%0A            return new SimpleDateFormat(%22yyyy/MM/dd hh:mm:ss%22).format(date
 );%0A
-%0A
         
 retu
@@ -2035,34 +2035,9 @@
     
-return builder.toString();
+%7D
 %0A   

Fix date formatting in StringUtils.dateToString