本文整理汇总了Scala中java.util.GregorianCalendar类的典型用法代码示例。如果您正苦于以下问题:Scala GregorianCalendar类的具体用法?Scala GregorianCalendar怎么用?Scala GregorianCalendar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GregorianCalendar类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: TransacaoCPGF
//设置package包名称以及导入依赖的类
package model
import java.util.GregorianCalendar
import java.util.Calendar
case class TransacaoCPGF(
idPortador: String,
idFavorecido: String,
codigoOrgaoSuperior: Int,
nomeOrgaoSuperior: String,
codigoOrgaoSubordinado: Int,
nomeOrgaoSubordinado: String,
codigoUnidadeGestora: Int,
nomeUnidadeGestora: String,
anoExtrato: Int,
mesExtrato: Int,
CPFPortador: String,
nomePortador: String,
tipoTransacao: String,
dataTransacao: GregorianCalendar,
CNPJCPFFavorecido: String,
nomeFavorecido: String,
valorTransacao: Double){
def dateToString(cal: Calendar) = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DAY_OF_MONTH)
def getDateFormated = dateToString(dataTransacao)
}
示例2: CronScheduleSpec
//设置package包名称以及导入依赖的类
package model
import java.text.ParseException
import java.util.GregorianCalendar
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatestplus.play.PlaySpec
@RunWith(classOf[JUnitRunner])
class CronScheduleSpec extends PlaySpec {
"Cron scheduler" should {
"successfully parse cron entry for 10pm every day" in {
val cronSchedule = CronSchedule("0", "22", "*", "*", "?")
val date = new GregorianCalendar(2015, 10, 5, 21, 0).getTime
val expectedNextDate = new GregorianCalendar(2015, 10, 5, 22, 0).getTime
val nextDate = cronSchedule.nextRunAfter(date)
nextDate must be(expectedNextDate)
}
"Throw exception on creation if cron schedlue is invalid" in {
intercept[ParseException] {
CronSchedule("0", "22", "*", "*", "*")
}
}
}
}
示例3: Helpers
//设置package包名称以及导入依赖的类
package com.scxmpp.util
import java.net.URLEncoder
import java.text.SimpleDateFormat
import java.util.{GregorianCalendar, TimeZone, Locale}
import java.util.regex.Pattern
object Helpers {
private val XML_DATE_FORMAT: String = "yyyy-MM-dd'T'HH:mm:ss"
def getXmlTimestamp: String = {
val dateFormatter = new SimpleDateFormat(XML_DATE_FORMAT, Locale.US)
dateFormatter.setTimeZone(TimeZone.getTimeZone("GMT"))
val time = new GregorianCalendar()
dateFormatter.format(time.getTime)
}
def makePattern(s: String): Pattern =
Pattern.compile("^\\Q" + s.replace("?", "\\E.\\Q").replace("*", "\\E.*\\Q") + "\\E$")
def urlEncode(s: String) = URLEncoder.encode(s, "UTF-8")
def unixTimestamp: Long = System.currentTimeMillis / 1000
}
示例4: FileUtils
//设置package包名称以及导入依赖的类
package models
import java.util.GregorianCalendar
import java.text.SimpleDateFormat
import java.util.Properties
import java.io.FileInputStream
import scala.io._
object FileUtils {
var tmpPath = models.Config.home_path + "/public/temp"
def getFile(fileName: String) = scala.io.Source.fromFile(fileName).getLines().toSet
def readPropertiesFile(file: String) = {
var defaultProps = new Properties()
var in = new FileInputStream(file)
defaultProps.load(in)
in.close()
defaultProps
}
def getNewFilename(prefix: String, suffix: String, path: String) = {
val calendar = new GregorianCalendar()
val sdf = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS")
val datetime = sdf.format(calendar.getTime())
path + "/" + prefix + "_" + datetime.toString() + suffix
}
def getFileToString(filename: String): String = {
try {
val lines = scala.io.Source.fromFile(filename).mkString
lines
} catch {
case e: Throwable => {
println(e)
""
}
}
}
}
示例5: Csv
//设置package包名称以及导入依赖的类
package web
import java.text.SimpleDateFormat
import java.util.{Locale, GregorianCalendar, TimeZone}
import capture.CaptureFeatures
object Csv {
def convertToCsv(l: Seq[CaptureFeatures]): String = {
val header = "timestamp, tcpAddresses, tcpPorts, tcpSpeed, tcpFrameCount, udpAddresses, udpPorts, udpSpeed, udpFrameCount, icmpAddresses, icmpSpeed, icmpFrameCount, procLoad, ramUsage \n"
val a = l.map(el => convertToLine(el)).mkString("\n")
header + a + "\n"
}
private def convertToLine(d: CaptureFeatures): String = {
s"${toDateFormat(d.timestamp)}, ${d.tcpAddresses}, ${d.tcpPorts}, ${d.tcpSpeed}, ${d.tcpFrameCount}, " +
s"${d.udpAddresses}, ${d.udpPorts}, ${d.udpSpeed}, ${d.udpFrameCount}, " +
s"${d.icmpAddresses}, ${d.icmpSpeed}, ${d.icmpFrameCount}, ${d.procLoad}, ${d.ramUsage}"
}
private def toDateFormat(time: Long): String = {
val sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US)
val calendar = new GregorianCalendar(TimeZone.getTimeZone("US/Central"))
calendar.setTimeInMillis(time)
sdf.format(calendar.getTime)
}
def convertToCsvAnomalySignal(times: Seq[Long], anom1: Seq[Double], anom2: Seq[Double]): String = {
val header = "timestamp, anomaly score kMeans, anomaly score distribution eval\n"
val data = (times zip anom1 zip anom2).map(el => toDateFormat(el._1._1) + "," + el._1._2.toString + "," +
el._2.toString).mkString("\n")
header + data + "\n"
}
}