Scala Date Date Processing

Source: Internet
Author: User
Tags dateformat
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 ())}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.