草庐IT

random-time-generation

全部标签

java - 如何在 Spring 中抽象出 java.time.Clock 用于测试目的

我有一个关于Timedependentunittests的问题假设我构建了包含服务接口(interface)及其实现的Spring应用程序如果我想在测试中更改时钟,我将不得不“污染”生产代码和接口(interface),例如setClock方法如下:publicinterfaceMyService{voidheavyBusinessLogic();voidsetClock(Clockclock);}@ServicepublicclassMyServiceImplimplementsMyService{privateClockclock=Clock.systemDefaultZone()

java - 如何从 SQL Time (String) 解析为 java.sql.Time?

我有一个带有时间字段的数据库。当我使用php获取字段时,我通过JSON接收作为字符串的时间字段。我收到的字符串是这样的:08:00:00好的,这里一切正常,但我需要java.sql.Time格式的字符串。有什么简单的方法吗?代码:Stringhour1=retrieveHourFromPHPSqlConnection();Timea=hour1;如何将hour1转化为时间?谢谢 最佳答案 来自Javadoc我建议你使用这个:java.sql.TimemyTime=java.sql.Time.valueOf(hour1);采用hh:m

Java 9 : Generating a runtime image with JLink using 3rd party jars

我想创建一个包含第3方jar的Java9运行时镜像。我制作了一个简单的Java项目(我们称之为Example)来调用实用程序jar(我们称之为ExampleUtil.jar)。Example包含src目录中的module-info.java并在Eclipse中运行良好(我添加了ExampleUtil.jar作为模块依赖)。如果我打电话:jlink-v--module-path"C:\ProgramFiles\Java\jdk-9.0.4\jmods";C:\Temp--add-modulescom.example.steven--outputC:\Temp\image.steven--

你是怎么理解ES6中 Generator的?使用场景?

这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助一、介绍Generator函数是ES6提供的一种异步编程解决方案,语法行为与传统函数完全不同回顾下上文提到的解决异步的手段:回调函数promise那么,上文我们提到promsie已经是一种比较流行的解决异步方案,那么为什么还出现Generator?甚至async/await呢?该问题我们留在后面再进行分析,下面先认识下GeneratorGenerator函数执行 Generator 函数会返回一个遍历器对象,可以依次遍历 Generator 函数内部的每一个状态形式上,Generator函数是一个普通函数,但是有两个特征:functi

java - 用于 java.time.LocalDateTime 的 DynamoDBMapper

我在我的Java应用程序中使用java.time.LocalDateTime。我还尝试使用DynamoDBMapper并通过注释保存LocalDateTime变量。不幸的是我收到以下错误:DynamoDBMappingException:Unsupportedtype:classjava.time.LocalDateTime有没有办法在不使用DynamoDBMarshalling的情况下进行此映射? 最佳答案 没有任何AWSDynamoDBJavaSDK无法在不使用任何注释的情况下本地映射java.time.LocalDateTim

java - 使用 java.time 根据时区转换时间

如何根据LocalDateTime中的时区更改时间,这里我已经建立了一个时区为EST的日期,现在我需要找到UTC的相应时间。请帮我解决这个问题Stringstr="16Jun2015_153556";DateTimeFormatterformatter=DateTimeFormatter.ofPattern("ddMMMyyyy_HHmmss");formatter.withZone(ZoneId.of("EST5EDT"));LocalDateTimedateTime=LocalDateTime.parse(str,formatter); 最佳答案

java - joda-time DateTime.with*() 的性能问题

有没有快速创建DateTime实例并将分\秒\毫秒设置为0的方法?目前我正在使用以下代码:privateDateTimecreateDateTime(java.util.Datedate,org.joda.time.Chronologychronology){DateTimedateTime=newDateTime(date,chronology);dateTime=dateTime.withMinuteOfHour(0);dateTime=dateTime.withSecondOfMinute(0);dateTime=dateTime.withMillisOfSecond(0);re

java - Joda Time : Get first/second/last sunday of month

在纯Java中,我有这段代码可以获取该月的最后一个星期日。CalendargetNthOfMonth(intn,intday_of_week,intmonth,intyear){CalendarcompareDate=Date(1,month,year);compareDate.set(DAY_OF_WEEK,day_of_week);compareDate.set(DAY_OF_WEEK_IN_MONTH,n);returncompareDate;}//UsageCalendarlastSundayOfNovember=getNthOfMonth(-1,SUNDAY,NOVEMBER

java - Joda Time LocalDate(Object instant, DateTimeZone zone) 构造函数的用途

JodaTime的LocalDate将自己描述为:LocalDateisanimmutabledatetimeclassrepresentingadatewithoutatimezone.但是有一个LocalDate(Objectinstant,DateTimeZonezone)接受时区的构造函数。如果对象是无时区的,那么时区构造函数的目的是什么?构造函数JavaDocs指出:ConstructsaninstancefromanObjectthatrepresentsadatetime,forcingthetimezonetothatspecified.我不知道“强制指定时区”是什么意

cmake Visual Studio Proj Generator和Per Config链接

我有一个要在VisualStudio2017中构建的程序,我也希望CMAKE生成ProJ/SLN文件,因此我使用VisualStudioGenerator2017AMD64在Windows10上使用CMAKE3.8.2。事实是,我的程序需要在调试或发行版中构建时需要链接不同的库,我希望生成的vsproj在VisualStudio内切换配置时正确选择要链接的正确库。可以通过手动编辑ProJ文件可以轻松实现这一点,但我希望Cmake为我做。在cmakelists.txt中,我在两个列表中收集了相关库LIBS_DEBUG和LIBS_RELEASE,到目前为止,我尝试了以下内容:优化/调试关键字tar