Package com.juanpi.bi.sc_utils import Java.text.SimpleDateFormat import java.util. {Calendar, Date} import com.juanpi.bi.streaming.DateHour import org.joda.time.DateTime/** * Created by JUANPI on 2015/
8/18. */Object Dateutils {def datehour (milliseconds:long):D atehour = {val datetime = new DateTime (milliseconds) Da Tehour (DateTime.ToString ("Yyyy-mm-dd"), DateTime.ToString ("H"))}/** * return date plus gu_id last, as log file save directory * * @param milliseconds * @param gu_id * @return/def dateguidpartitions (Milliseconds:long, gu_id:string): S Tring = {val DateTime = new DateTime (milliseconds) Val date = datetime.tostring ("Yyyy-mm-dd") val Gu_hex = (g U_id.last). ToLower S "Date=${date}/gu_hash=${gu_hex}"}/** * returns YYYY-MM-DD format Date * * @param Milliseco NDS * @return/def datestr (milliseconds:long): String = {val DateTime = new DateTime (milliseconds) d Atetime.tostring ("Yyyy-mm-dd")}/** * accepts a timestampparameters, return date and hour * * @param milliseconds * @return/def datehourstr (Milliseconds:long): (string, string) =
{val datetime = new DateTime (milliseconds) (DateTime.ToString ("Yyyy-mm-dd"), DateTime.ToString ("H"))}/** * * @return Return the current date string/def getdatenow (): string={val now:date = new Date () Val dateformat:simpledate Format = new SimpleDateFormat ("Yyyy-mm-dd") val dt = Dateformat.format (now) DT}/** * Specify date and Interval days, return the specified date Date of the first N day date-n days * @param dt * @param interval * @return/def getdaysbefore (Dt:date, Interval:in T): String = {val Dateformat:simpledateformat = new SimpleDateFormat ("Yyyy-mm-dd") val Cal:calendar = Calendar.
GetInstance () cal.settime (DT); Cal.add (calendar.date,-interval) val yesterday = Dateformat.format (Cal.gettime ()) Yesterday}/** * designation Date and Interval days, returning the date of N days before the specified date: Date + N Day * @param dt * @param interval * @return/def GETDAYslater (Dt:date, interval:int): String = {val Dateformat:simpledateformat = new SimpleDateFormat ("Yyyy-mm-dd")
Val Cal:calendar = calendar.getinstance () cal.settime (DT); Cal.add (calendar.date, + interval) val yesterday = Dateformat.format (Cal.gettime ()) Yesterday}/** * 201
7-01-17 A Week Ago is 2017-01-07 * @return/def getweekagodatestr (): String = {val dt:date = new Date ()
Val dtstr = getdaysbefore (dt, 7) Dtstr}/** * 2017-01-17 A Week later is 2017-01-21 * @return
*/def GETWEEKLATERDATESTR (): String = {val dt:date = new Date () Val dtstr = getdayslater (dt, 7) dtstr Def getyesterday (): String = {//calendar.date val dt:date = new DATE () val yesterday = Getdaysbefore (d T, 1) return yesterday} def main (args:array[string]) {println (Getweekagodatestr ()) println (getweeklate Rdatestr ())}}