将毫秒转换为Joda Date Time或转换为0000区域

时间:2015-06-08 13:03:32

标签: android jodatime

请告诉我如何将毫秒转换为joda日期时间??

object PicklingIteratorExample extends App {

    import scala.pickling.Defaults._
    import scala.pickling.binary._
    import scala.pickling.static._

    case class Person(name: String, age: Int)

    val personsIt = Iterator.from(0).take(10).map(i => Person(i.toString, i))
    val pklsIt = personsIt.map(_.pickle)

    ??? // Write to disk
    val readIt: Iterator[Person] = ??? // Read from disk and unpickle
} 

甚至尝试过

formatter = DateTimeFormat.forPattern("dd/MM/yyyy'T'HH:mm:ss").withZone(DateTimeZone.forOffsetHoursMinutes(00, 00));

3 个答案:

答案 0 :(得分:28)

@Adam S给出的答案几乎没问题。但是,我更愿意明确指定时区。如果不指定它,您将在系统时区中获得构造的DateTime - 实例。但是你想要区域" 0000" (世界标准时间)?然后寻找替代constructor

String milliseconds = "14235453511";
DateTime someDate = new DateTime(Long.valueOf(milliseconds), DateTimeZone.UTC);
System.out.println(someDate); // 1970-06-14T18:17:33.511Z

答案 1 :(得分:14)

a constructor that takes milliseconds

long milliseconds = 14235453511;
DateTime someDate = new DateTime(milliseconds);

答案 2 :(得分:-2)

您可以使用此

Calendar calendar = new GregorianCalendar();

        DateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss z");

        formatter.setCalendar(calendar);
        String timeZone = "GMT+2:00";
        formatter.setTimeZone(TimeZone.getTimeZone(timeZone));

        String time = formatter.format(calendar.getTime());

        System.out.println(time);

我希望这会对你有所帮助