Yes , things go well now.  It is a problem of SimpleDateFormat. Thank you all.

------------------ 原始邮件 ------------------
发件人: "Dumas Hwang";<>;
发送时间: 2015年6月27日(星期六) 晚上8:16
收件人: "Tathagata Das"<>;
抄送: "Emrehan Tüzün"<>; "Sea"<>; "dev"<>; "user"<>;
主题: Re: Time is ugly in Spark Streaming....

Java's SimpleDateFormat is not thread safe.  You can consider using DateTimeFormatter if you are using Java 8 or Joda-time

On Sat, Jun 27, 2015 at 3:32 AM, Tathagata Das <> wrote:
Could you print the "time" on the driver (that is, in foreachRDD but before RDD.foreachPartition) and see if it is behaving weird?


On Fri, Jun 26, 2015 at 3:57 PM, Emrehan Tüzün <> wrote:

On Fri, Jun 26, 2015 at 12:30 PM, Sea <> wrote:

Hi, all

I find a problem in spark streaming, when I use the time in function foreachRDD... I find the time is very interesting.
val messages = KafkaUtils.createDirectStream[String, String, StringDecoder, StringDecoder](ssc, kafkaParams, topicsSet) => createGroup(x._2, dimensions)).groupByKey().foreachRDD((rdd, time) => {
try {
if (!rdd.partitions.isEmpty) {
rdd.foreachPartition(partition => {
handlePartition(partition, timeType, time, dimensions, outputTopic, brokerList)
} catch {
case e: Exception => e.printStackTrace()

val dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
var date = dateFormat.format(new Date(time.milliseconds))

Then I insert the 'date' into Kafka , but I found .....