Pages

Sunday, November 24, 2013

Work with PHP and MsSQL

http://msdn.microsoft.com/en-us/library/cc296170.aspx

Tuesday, November 12, 2013

Creating Routines in Talend

package routines;
import java.util.Date;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;


public class calculateTime {

    /**
     * helloExample: not return value, only print "hello" + message.
     *
     *
     * {talendTypes} String
     *
     * {Category} User Defined
     *
     * {param} string("world") input: The string need to be printed.
     *
     * {example} helloExemple("world") # hello world !.
     */
    public static void helloExample(String message) {
        if (message == null) {
            message = "World"; //$NON-NLS-1$
        }
        System.out.println("Hello " + message + " !"); //$NON-NLS-1$ //$NON-NLS-2$
    }
   
    public static String printCurrentTime() {
        Date dNowj1 = new Date();
        SimpleDateFormat ftj1 = new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
       
        return ftj1.format(dNowj1);
    }
   
    public static String getCurrentTime() {
        Date dNowj1 = new Date();
        SimpleDateFormat ftj1 = new SimpleDateFormat ("yy/MM/dd HH:mm:ss");
       
        return ftj1.format(dNowj1);
    }
   
    public static String getTimeDiff(String dateStart,String dateStop) {
       
        // Custom date format
        SimpleDateFormat format = new SimpleDateFormat("yy/MM/dd HH:mm:ss"); 

        Date d1 = null;
        Date d2 = null;
       
        try {
            d1 = format.parse(dateStart);
            d2 = format.parse(dateStop);
        } catch (ParseException e) {
            e.printStackTrace();
        }        

        // Get msec from each, and subtract.
        long diff = d2.getTime() - d1.getTime();
        long diffSeconds = diff / 1000%60;        
        long diffMinutes = diff / (60 * 1000)%60;        
        long diffHours = diff / (60 * 60 * 1000)%60;    
       
        String timeDiff = diffHours+":" + diffMinutes+":"+ diffSeconds;
        return timeDiff;
    }
   
    public static void wtireLogs(String FilePath, String LogContents) {
        File file = new File(FilePath);
         
        try {
            FileWriter fileWriter = new FileWriter(file,true);
            BufferedWriter bufferFileWriter = new BufferedWriter(fileWriter);
            fileWriter.append(LogContents);
            bufferFileWriter.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

Open source Charts build easily