Kettle案例三十五:获取时间

2020-03-25  本文已影响0人  千客

流程图

image.png
import java.text.ParseException;
import java.util.Date;

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
    Object[] r = getRow(); 
    if (r == null)
    {
        setOutputDone();
        return false;
    }

    
    
    if (first)
    {
        first = false;
    }

    String tmp_time = get(Fields.In,"date").getString(r);
    Long time_stamp = dateToStamp(tmp_time);
    r = createOutputRow(r, data.outputRowMeta.size()); 
    get(Fields.Out, "_time_stamp").setValue(r,time_stamp);
    putRow(data.outputRowMeta,r);
    return true;
}

public static Long dateToStamp(String s)
{
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();
    try
    {
        date = simpleDateFormat.parse(s);
    }
    catch (ParseException e)
    {   
    }
    Long ts = date.getTime();
    return ts;
}
上一篇下一篇

猜你喜欢

热点阅读