本文整理汇总了Scala中java.util.Date类的典型用法代码示例。如果您正苦于以下问题:Scala Date类的具体用法?Scala Date怎么用?Scala Date使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Date类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: DateUtil
//设置package包名称以及导入依赖的类
package com.github.youzp
import java.text.SimpleDateFormat
import java.util.{Calendar, Date}
object DateUtil {
private val dateFmt = "yyyy-MM-dd"
def today(): String = {
val date = new Date
val sdf = new SimpleDateFormat(dateFmt)
sdf.format(date)
}
def yesterday(): String = {
val calender = Calendar.getInstance()
calender.roll(Calendar.DAY_OF_YEAR, -1)
val sdf = new SimpleDateFormat(dateFmt)
sdf.format(calender.getTime())
}
def daysAgo(days: Int): String = {
val calender = Calendar.getInstance()
calender.roll(Calendar.DAY_OF_YEAR, -days)
val sdf = new SimpleDateFormat(dateFmt)
sdf.format(calender.getTime())
}
}
示例2: Location
//设置package包名称以及导入依赖的类
package domain.company
import java.util.Date
import play.api.libs.json.Json
case class Location(company:String,
id:String,
name:String,
locationTypeId:String,
code:String,
latitude:String,
longitude:String,
parentId:String,
state:String,
date:Date)
object Location{
implicit val location = Json.format[Location]
}
示例3: GitInfo
//设置package包名称以及导入依赖的类
package git
import java.util.Date
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
import scala.language.experimental.macros
import scala.reflect.macros.blackbox
import scala.collection.JavaConversions._
object GitInfo {
def lastRevCommitName(): String = macro lastRevCommitName_impl
def lastRevCommitName_impl(c: blackbox.Context)(): c.Expr[String] = {
val git = Git.wrap(loadGitRepositoryfromEnclosingSourcePosition(c))
import c.universe._
c.Expr[String](q""" ${lastRevCommitName(git)} """)
}
def lastRevCommitAuthor(): String = macro lastRevCommitAuthor_impl
def lastRevCommitAuthor_impl(c: blackbox.Context)(): c.Expr[String] = {
val git = Git.wrap(loadGitRepositoryfromEnclosingSourcePosition(c))
import c.universe._
c.Expr[String](q""" ${lastRevCommitAuthorName(git)} """)
}
def currentBranch(): String = macro currentBranch_impl
def currentBranch_impl(c: blackbox.Context)(): c.Expr[String] = {
import c.universe._
c.Expr[String](q""" ${loadGitRepositoryfromEnclosingSourcePosition(c).getBranch}""")
}
def lastRevCommitMessage(): String = macro lastRevCommitMessage_impl
def lastRevCommitMessage_impl(c: blackbox.Context)(): c.Expr[String] = {
import c.universe._
val git = Git.wrap(loadGitRepositoryfromEnclosingSourcePosition(c))
c.Expr[String](q""" ${lastRevCommitMessage(git)} """)
}
def lastRevCommitTime(): String = macro lastRevCommitTime_impl
def lastRevCommitTime_impl(c: blackbox.Context)(): c.Expr[String] = {
import c.universe._
val git = Git.wrap(loadGitRepositoryfromEnclosingSourcePosition(c))
c.Expr[String](q""" ${lastRevCommitDate(git)} """)
}
}
示例4: BaseBDBEntity
//设置package包名称以及导入依赖的类
package db
import java.util.{Date, UUID}
import com.fasterxml.jackson.databind.{SerializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
import tools._
import common._
import Tool._
class BaseBDBEntity[+Self <: BaseBDBEntity[Self]](tableName: String) extends BDBEntity(tableName) {
def toJson: String = {
BaseBDBEntity.map.writeValueAsString(this)
}
def fromJson(json: String): Self = {
BaseBDBEntity.map.readValue(json, this.getClass).asInstanceOf[Self]
}
//????????????
def changeUpdateBean(): Self = {
fromJson(toJson)
}
override def queryById(id: String, fields: String*): Option[Self] = {
super.queryById(id,fields:_*) map (_.asInstanceOf[Self])
}
override def queryByIds(idName: String, ids: List[Long], fields: String*): List[Self] = {
super.queryByIds(idName,ids,fields:_*) map (_.asInstanceOf[Self])
}
//????????????
override def queryPage(where: String, pageNum: Int, pageSize: Int, fields: String*):List[Self] = {
val list = super.queryPage(where, pageNum, pageSize,fields: _*)
list map (_.asInstanceOf[Self])
}
}
object BaseBDBEntity {
private val map = new ObjectMapper() with ScalaObjectMapper
map.registerModule(DefaultScalaModule)
map.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
}
//??????
class LoanData(val id:String=UUID.randomUUID().toString,val Title:String="",val text:String="",val createTime:Date=new Date())extends BaseBDBEntity[LoanData]("LoanData")
示例5: genericEncoder
//设置package包名称以及导入依赖的类
package io.gustavoamigo.quill.pgsql.encoding.range.datetime
import java.sql.{PreparedStatement, Types}
import java.time.{LocalDate, ZonedDateTime, LocalDateTime}
import java.util.Date
import io.getquill.source.jdbc.JdbcSource
trait Encoders {
this: JdbcSource[_, _] =>
import Formatters._
private def genericEncoder[T](valueToString: (T => String)): Encoder[T] = {
new Encoder[T] {
override def apply(index: Int, value: T, row: PreparedStatement) = {
val sqlLiteral = valueToString(value)
row.setObject(index + 1, sqlLiteral, Types.OTHER)
row
}
}
}
private def tuple[T](t: (T, T))(valToStr: T => String) = s"[${valToStr(t._1)}, ${valToStr(t._2)}]"
implicit val dateTupleEncoder: Encoder[(Date, Date)] = genericEncoder(tuple(_)(formatDate))
implicit val localDateTimeTupleEncoder: Encoder[(LocalDateTime, LocalDateTime)] =
genericEncoder(tuple(_)(formatLocalDateTime))
implicit val zonedDateTimeTupleEncoder: Encoder[(ZonedDateTime, ZonedDateTime)] =
genericEncoder(tuple(_)(formatZonedDateTime))
implicit val dateTimeTupleEncoder: Encoder[(LocalDate, LocalDate)] =
genericEncoder(t => s"[${formatLocalDate(t._1)}, ${formatLocalDate(t._2)})")
}
示例6: HomeController
//设置package包名称以及导入依赖的类
package controllers
import java.security.MessageDigest
import java.util.Date
import javax.inject._
import actors.MyWebSocketActor
import akka.actor.ActorSystem
import akka.stream.Materializer
import akka.stream.scaladsl.Flow
import play.api._
import play.api.libs.json.JsValue
import play.api.libs.streams.ActorFlow
import play.api.mvc._
import scala.concurrent.{ExecutionContext, Future}
@Singleton
class HomeController @Inject()(implicit system: ActorSystem, materializer: Materializer) extends Controller with ApiSecurity {
def index = Action.async { implicit request =>
Future.successful(
Ok(views.html.index())
)
}
def websocket = WebSocketRequest
}
trait ApiSecurity { this: Controller =>
private[this] val tokenName = "sessionId"
private[this] def hash(s: String) = MessageDigest.getInstance("SHA-256").digest(s.getBytes("UTF-8")).map("%02x".format(_)).mkString("")
implicit class ResultWithToken(result: Result)(implicit request: RequestHeader) {
def withToken: Result = {
request.session.get(tokenName) match {
case Some(sessionId) => result
case None => result.withSession(tokenName -> hash(new Date().getTime + request.remoteAddress))
}
}
}
def WebSocketRequest(implicit system: ActorSystem, materializer: Materializer) =
WebSocket.acceptOrResult[JsValue, JsValue] { request =>
Future.successful(request.session.get(tokenName) match {
case None => Left(Forbidden)
case Some(_) => Right(ActorFlow.actorRef(MyWebSocketActor.props))
})
}
}
示例7: Application
//设置package包名称以及导入依赖的类
import java.text.SimpleDateFormat
import java.util.concurrent.TimeUnit
import java.util.{Date, Properties}
import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}
object Application extends App {
val formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
val simIDs = 10000 to 99999 //99000
val brokers = "192.168.100.211:6667,192.168.100.212:6667,192.168.100.213:6667";
val topic = "newTest";
val props = new Properties
props.put("bootstrap.servers", brokers)
props.put("client.id", "Producer")
props.put("key.serializer", "org.apache.kafka.common.serialization.IntegerSerializer")
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer")
val producer = new KafkaProducer[Integer, String](props)
while (true) {
for (simID <- simIDs) {
val data = Data(
"64846867247",
"?D" + simID,
formatter.format(new Date()),
121.503,
31.3655,
78,
0,
42,
52806.7
)
// println(Data.getString(data))
producer.send(new ProducerRecord[Integer, String](topic, Data.getString(data)))
// TimeUnit.NANOSECONDS.sleep(100)
}
println("-------------------------------"+new Date())
TimeUnit.MINUTES.sleep(18)
}
}
示例8: EMail
//设置package包名称以及导入依赖的类
package tools
import javax.mail.internet.{InternetAddress, MimeMessage}
import javax.mail._
import javax.mail._
import java.util.Date
class EMail(email: String, password: String, smtp: String) {
val session = getSession
def sendMail(address:String,title:String,body:String)={
try{
val msg = new MimeMessage(session)
msg.setFrom(new InternetAddress(email))
msg.setRecipients(Message.RecipientType.TO, address)
msg.setSubject(title)
msg.setSentDate(new Date())
if (body.contains("<") && body.contains(">")) {
msg.setContent(body, "text/html;charset=utf-8")
} else {
msg.setText(body)
}
Transport.send(msg)
true
}catch {
case th:Throwable=>th.printStackTrace()
false
}
}
private def getSession() = {
val SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"
val props = System.getProperties()
props.setProperty("mail.smtp.host", smtp)
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY)
props.setProperty("mail.smtp.socketFactory.fallback", "false")
props.setProperty("mail.smtp.port", "465")
props.setProperty("mail.smtp.socketFactory.port", "465")
props.put("mail.smtp.auth", "true")
val ah = new Authenticator() {
override protected def getPasswordAuthentication(): PasswordAuthentication = {
new PasswordAuthentication(email, password)
}
}
Session.getDefaultInstance(props, ah)
}
}
示例9: Common
//设置package包名称以及导入依赖的类
package models
import java.util.Date
import reactivemongo.bson.{BSONDateTime,BSONReader,BSONWriter}
object Common {
val objectIdRegEx = """[a-fA-F0-9]{24}""".r
}
object BSONProducers {
implicit object DateWriter extends BSONWriter[Date,BSONDateTime]{
def write(dt:Date) : BSONDateTime = BSONDateTime(dt.getTime)
}
implicit object DateReader extends BSONReader[BSONDateTime,Date]{
def read(dt:BSONDateTime) : Date = new Date(dt.value)
}
}
示例10: WSGitHubCommit
//设置package包名称以及导入依赖的类
package models
import java.text.SimpleDateFormat
import java.util.Date
import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, Json, Reads, Writes}
case class WSGitHubCommit(committer: String, date: Date) {
def getFormatedDate: String = {
val dateFormat: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd")
dateFormat.format(date)
}
}
object WSGitHubCommit {
implicit val gitHubProjectSummaryReads: Reads[WSGitHubCommit] = (
(JsPath \ "email").read[String] and
(JsPath \ "date").read[Date]
)(WSGitHubCommit.apply _)
implicit val gitHubProjectSummaryWriters = new Writes[WSGitHubCommit] {
def writes(gitHubProjectSummary: WSGitHubCommit) = Json.obj(
"email" -> gitHubProjectSummary.committer,
"date" -> gitHubProjectSummary.date
)
}
}
示例11: requestClearance
//设置package包名称以及导入依赖的类
package name.kaeding.fibs.ib.impl
) {
private[this] var lastReq: Long = 0
def requestClearance = this.synchronized {
import java.util.Date
val now = new Date().getTime
val timeSince = now - lastReq
if (timeSince < minTimeBetweenRequests) {
Thread.sleep(minTimeBetweenRequests - timeSince)
}
lastReq = new Date().getTime
}
}
示例12: Total
//设置package包名称以及导入依赖的类
package sample.stream_actor
import akka.Done
import akka.actor.Actor
import sample.stream_actor.Total.Increment
import java.text.SimpleDateFormat
import java.util.{Date, TimeZone}
object Total {
case class Increment(value: Long, avg: Double, id: String)
}
class Total extends Actor {
var total: Long = 0
override def receive: Receive = {
case Increment(value, avg, id) =>
println(s"Recieved $value new measurements from id: $id - Avg wind speed is: $avg")
total = total + value
val date = new Date()
val df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
df.setTimeZone(TimeZone.getTimeZone("Europe/Zurich"))
println(s"${df.format(date) } - Current total of all measurements: $total")
sender ! Done
}
}
示例13: Grade
//设置package包名称以及导入依赖的类
package domain.payroll.salary
import java.util.Date
import org.joda.time.DateTime
import play.api.libs.json.Json
case class Grade(organisationId: String,
gradeId: String,
name: String,
numberOfNotches: Int,
lowerAmount: BigDecimal,
topAmount: BigDecimal,
currencyId: String,
date: DateTime,
notes: String)
object Grade {
implicit val gradeFmt = Json.format[Grade]
}
示例14: Language
//设置package包名称以及导入依赖的类
package walfie.gbf.raidfinder
import java.util.Date
package object domain {
type BossName = String
type TweetId = Long
type RaidImage = String
}
package domain {
sealed trait Language
object Language {
case object English extends Language
case object Japanese extends Language
}
case class RaidInfo(
tweet: RaidTweet,
boss: RaidBoss
)
case class RaidTweet(
bossName: BossName,
raidId: String,
screenName: String,
tweetId: TweetId,
profileImage: String,
text: String,
createdAt: Date,
language: Language
)
case class RaidBoss(
name: BossName,
level: Int,
image: Option[RaidImage],
lastSeen: Date,
language: Language
)
trait FromRaidTweet[T] {
def from(raidTweet: RaidTweet): T
}
object FromRaidTweet {
def apply[T](fromF: RaidTweet => T) = new FromRaidTweet[T] {
def from(raidTweet: RaidTweet): T = fromF(raidTweet)
}
val Identity: FromRaidTweet[RaidTweet] =
FromRaidTweet[RaidTweet](identity)
}
}
示例15: ReadPostProcessingSuite
//设置package包名称以及导入依赖的类
package com.github.xubo245.gcdss.adam.postProcessing
import java.text.SimpleDateFormat
import java.util.Date
import com.github.xubo245.gcdss.utils.GcdssAlignmentFunSuite
import org.bdgenomics.adam.cli.Transform
class ReadPostProcessingSuite extends GcdssAlignmentFunSuite {
val iString = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())
test("test sort") {
val fqFile = "file/callVariant/input/sam/unordered.sam"
// val out = "file/callVariant/output/sam/ordered.sam"+iString
val out = "file/callVariant/output/sam/ordered"+iString+".sam"
ReadPostProcessing.sort(sc, fqFile, out)
}
test("test recalibrate_base_qualities with known_snps") {
val fqFile = "file/callVariant/input/sam/unordered.chr.sam"
val vcfFile = "file\\callVariant\\input\\vcf\\vcfSelectAddSequenceDictionaryWithChr.adam"
// val out = "file/callVariant/output/sam/orderedrecalibrate_base_qualities.sam"
val out = "file/callVariant/output/sam/orderedrecalibrate_base_qualities.sam"
ReadPostProcessing.BQSR(sc, fqFile, out,vcfFile)
}
test("test realign_indels") {
val fqFile = "file/callVariant/input/sam/unordered.sam"
// val out = "file/callVariant/output/sam/realign_indels.sam"
val out = "file/callVariant/output/sam/realign_indels"+iString+".sam"
ReadPostProcessing.realignIndel(sc, fqFile, out)
}
test("test mark_duplicate_reads") {
val fqFile = "file/callVariant/input/sam/unordered.sam"
// val out = "file/callVariant/output/sam/mark_duplicate_reads.sam"
val out = "file/callVariant/output/sam/mark_duplicate_reads"+iString+".sam"
ReadPostProcessing.sort(sc, fqFile, out)
}
}