草庐IT

TIME_FORMAT

全部标签

java - 我们可以使用 String.format() 来填充/前缀所需长度的字符吗?

java.lang.String.format(Stringstr,Stringstr1)能否用于添加特定字符的前缀。我可以对这样的数字执行此操作:intsendID=202022;StringusiSuffix=String.format("%032d",sendID);它生成一个长度为32的String并在左边填充0:000000000000000000000000000202022当sendID是String时如何实现同样的事情:StringsendID="AABB";我想要这样的输出:0000000000000000000000000000AABB

java - JAX-WS 和 Joda-Time?

如何编写一个JAX-WS服务,使我的@WebMethod的@WebParam是一个像DateTime这样的Joda-Time类?参数上的@XmlTypeAdapter会起作用吗?我正在部署到GlassFish2.1。让我澄清一下这个问题,因为到目前为止,这两个答案都侧重于将自定义类型绑定(bind)到现有的JAXB类,这是相关的,但不是我要问的问题。如何使以下@WebService接受jodaDateTime对象作为参数?importjavax.jws.WebMethod;importjavax.jws.WebParam;importjavax.jws.WebService;impor

java - String 类型中的方法 format(String, Object[]) 不适用于参数 (...)

这是我的代码:inthoursFormat=1,minsFormat=2,secsFormat=3;StringtimeFormat=String.format("%02d:%02d:%02d",hoursFormat,minsFormat,secsFormat);这给出了一个编译错误:Unresolvedcompilationproblem:Themethodformat(String,Object[])inthetypeStringisnotapplicableforthearguments(String,int,int,int)为什么会出现此错误,我该如何解决?

java - 使用 Java 8 java.time api 解析 ISO 时间戳(仅限标准版)

我无法从示例中的字符串中获取纪元的毫秒数。到目前为止,我已经尝试了这三种不同的方法,示例显示了最新的尝试。似乎总是归结为TemporalAccessor不支持ChronoField.如果我能成功构造一个Instant实例,我就可以使用toEpochMilli().StringdateStr="2014-08-16T05:03:45-05:00"TemporalAccessorcreationAccessor=DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(dateStr);InstantcreationDate=Instant.from(cre

java - 将 java.time 转换为日历

从java.time.Instant或java.time.ZonedDateTime获取Calendar对象的最简单方法是什么? 最佳答案 从ZonedDateTime即时获取Calendar非常简单,前提是您知道存在一个GregorianCalendar#from(ZonedDateTime)。方法。Threeten-devmailgroup中有讨论,关于为什么该方法不在Calendar类中。虽然不是很深入的讨论。但是,没有直接的方法可以将Instant转换为Calendar。你必须有一个中间状态:Instantinstant=I

java.time : Does the CET time zone considers daylight saving time?

我使用Java8的新java.time实现,想知道UTC到CET的输出时间转换结果。ZonedDateTimeutcTime=ZonedDateTime.of(2014,7,1,8,0,0,0,ZoneId.of("UTC"));ZonedDateTimecetTime=ZonedDateTime.ofInstant(utcTime.toInstant(),ZoneId.of("CET"));System.out.println("Summer-UTC-Time:"+utcTime);System.out.println("Summer-CET-Time:"+cetTime);Syst

java - 如何使用 String.format 将字符串居中?

publicclassDivers{publicstaticvoidmain(Stringargs[]){Stringformat="|%1$-10s|%2$-10s|%3$-20s|\n";System.out.format(format,"FirstName","Init.","LastName");System.out.format(format,"Real","","Gagnon");System.out.format(format,"John","D","Doe");Stringex[]={"John","F.","Kennedy"};System.out.format(St

java.time.DateTimeFormatter : Need ISO_INSTANT that always renders milliseconds

我正在尝试将围绕日期时间管理的各种代码混合清理到仅Java8java.time命名空间。现在我有一个关于默认DateTimeFormatter的小问题对于Instant.DateTimeFormatter.ISO_INSTANT格式化程序仅在不等于零时显示毫秒。纪元呈现为1970-01-01T00:00:00Z而不是1970-01-01T00:00:00.000Z。我做了一个单元测试来解释这个问题以及我们如何需要最终日期来相互比较。@Testpublicvoidjava8Date(){DateTimeFormatterformatter=DateTimeFormatter.ISO_IN

java - java.util.Date 和 Joda Time API 之间的差异

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:ShouldIuseJavadateandtimeclassesorgowitha3rdpartylibrarylikeJodaTime?关于何时值得使用JodaTime而不是基本的java.util.Date类,我可以使用一些指导。有什么好处?JodaTime是否可以让您做Date类不能做的任何事情,还是说它更容易使用还是什么?此外,关于JodaTime是否是标准API的一部分,我看到了相互矛盾的信息。是否标准?

java - 使用非 Comparable 类 : why a run-time exception, 而不是编译时错误创建 TreeSet?

如果我创建一个未实现Comparable的任意类,并尝试将其用作树集,它会在插入对象时在运行时抛出异常:publicclassFoo{}publicTreeSetfooSet=newTreeSet();fooSet.add(newFoo());//ThrowsaClassCastExceptionexceptionhere:Fooisnotcomparable我不是Java专家,但似乎以一种我没有预料到的方式动态输入(alaPython)。TreeSet的实现是否无法指定其泛型类型参数必须实现Comparable以便可以在编译时捕获?非泛型函数可以将接口(interface)作为参数;