分割时间工具

news/2025/2/22 1:17:38/

根据开始时间和结束时间 分割成若干随机时间

 public static List<PullUserConfigEntity> randomDateBySize(String start,String end,int size,Long id) throws ParseException {//输入 随机起始时间//解析时间Date d1 = simpleDateFormat.parse(start);long before = d1.getTime();//获取当前时间Date d2 = simpleDateFormat.parse(end);long after = d2.getTime();long randomDate = after-before;int[] randomArray = RandomUtils.getRandomArray((int) randomDate, size);List<PullUserConfigEntity>list=new ArrayList<>();for(int index:randomArray){PullUserConfigEntity pullUserConfig=new PullUserConfigEntity();pullUserConfig.setStartTime(TimeUtils.dateToStrLong(d1));d1.setTime(d1.getTime()+index);pullUserConfig.setEndTime(TimeUtils.dateToStrLong(d1));pullUserConfig.setId(id);list.add(pullUserConfig);}return list;}

根据开始时间和结束时间和固定间隔时间 分割成多个时间

 /*** 获取固定间隔时刻集合* @param start 开始时间* @param end 结束时间* @param interval 时间间隔(单位:分钟)* @return*/public static List< RobotConfigRelEntity> getIntervalTimeList(String start,String end,int interval,Long id){Date startDate = convertString2Date("yyyy-MM-dd HH:mm:ss",start);Date endDate = convertString2Date("yyyy-MM-dd HH:mm:ss",end);List< String> s = new ArrayList<>();while(startDate.getTime()<=endDate.getTime()){s.add(convertDate2String("yyyy-MM-dd HH:mm:ss",startDate));Calendar calendar = Calendar.getInstance();calendar.setTime(startDate);calendar.add(Calendar.SECOND,interval);if(calendar.getTime().getTime()>endDate.getTime()){if(!startDate.equals(endDate)){s.add(convertDate2String("yyyy-MM-dd HH:mm:ss",endDate));}startDate = calendar.getTime();}else{startDate = calendar.getTime();}}List<RobotConfigRelEntity> list = new ArrayList();for (int i = 0; i < s.size();i++ ) { //s.length=6,0+1,2+3,4+5RobotConfigRelEntity configRel=new RobotConfigRelEntity();if(i==0){configRel.setStartTime(s.get(i));configRel.setEndTime(s.get(i+1));}else{configRel.setStartTime(s.get(i-1));configRel.setEndTime(s.get(i));configRel.setRelationId(id);list.add(configRel);}}return list;}public static Date convertString2Date(String format, String dateStr) {SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);try {Date date = simpleDateFormat.parse(dateStr);return date;} catch (ParseException e) {e.printStackTrace();}return null;}public static String convertDate2String(String format,Date date) {SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);return simpleDateFormat.format(date);}

判断当前时间是否在开始和结束时间范围

 /*** 判断当前时间是否在[startTime, endTime]区间,注意三个参数的时间格式要一致* @param nowTime* @param startTime* @param endTime* @return 在时间段内返回true,不在返回false*/public static boolean isEffectiveDate(String startTime, String endTime) throws ParseException {SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String now = sdf.format(new Date());Date nowTime = sdf.parse(now);Date startTime1 = sdf.parse(startTime);Date endTime1 = sdf.parse(endTime);if (nowTime.getTime() == startTime1.getTime()|| nowTime.getTime() == endTime1.getTime()) {return true;}Calendar date = Calendar.getInstance();date.setTime(nowTime);Calendar begin = Calendar.getInstance();begin.setTime(startTime1);Calendar end = Calendar.getInstance();end.setTime(endTime1);return date.after(begin) && date.before(end);}


http://www.ppmy.cn/news/900656.html

相关文章

【Python】pydub按一定比特率、采样率压缩音频文件

使用Python第三方库pydub按一定bitrate&#xff0c;frame_rate压缩音频文件 安装pydub pip install pydub注&#xff1a; pydub支持wav格式音频读取&#xff0c;本文处理的是MP3格式&#xff0c;所以需要安装ffmpeg. Linux下安装ffmpeg sudo apt install ffmpeg读取、压缩MP…

格式工厂 wav 比特率_鸡娃常用工具系列一格式工厂(音频转换软件)

光光发发资料已经满足不了群众的需求了&#xff0c;因为好多人发现下载的文件是M4A&#xff0c;不知道怎么办&#xff0c;倾听者又播放不了&#xff0c;干着急。 倾听者支持的格式是官方的断句音频 lis&#xff0c;mp3/wma/wav格式&#xff0c;如是其它格式识别不了。我们一般常…

音频的比特率,码率

比特率 是指 每秒传送的比特&#xff08;bit&#xff09;数。单位bps(Bit per Second),比特率越高&#xff0c;传送数据速度越快。 声音中的比特率是指将模拟声音信号转换成数字声音信号后&#xff0c;单位时间内的二进制数据量&#xff0c;是间接衡量音频质量的一个指标。 比…

FFMPEG音频视频开发: 视频转码、合并、修改分辨率、比特率

一、环境介绍 操作系统介绍:win10 64位 FFMPEG版本: 4.4.2 QT版本: 5.12.6 二、FFMPEG下载 ubuntu系统下编译安装ffmpeg: https://blog.csdn.net/xiaolong1126626497/article/details/104919095 windos系统下安装ffmpeg: https://blog.csdn.net/xiaolong1126626497/arti…

音频相关知识:声道、采样率、采样位数、样本格式、比特率

目录 声道 采样率 采样位数 帧 样本的组合方式 样本格式 比特率 采样率、采样位数、比特率三者之间的关系 参考链接&#xff1a; 声道 当人听到声音时&#xff0c;能对声源进行定位&#xff0c;那么通过在不同的位置设置声源&#xff0c;就可以造就出更好的听觉感受&…

html5 录制mp3音频,支持采样率和比特率设置

13年的时候做过html5录音,一个问题是保存的wav格式文件很大,当初用了一个迂回的方式,上传到服务器后调用 lame 编码器转换,但由于文件大,上传较慢。不得不说,前端技术发展真是日新月异,有人实现了js版本的lame编码器,可以直接在浏览器端录制MP3音频。 lamejs介绍 最初有…

ffmpeg 比特率_为什么即使使用FFmpeg更改比特率,我的MP3文件大小也一样?

ffmpeg 比特率 If you are new to the process of converting audio files, then many of the details and how they work can be a bit confusing when you get unexpected results. So what do you do to fix the problem? Today’s SuperUser Q&A post has the answer …

PHP执行mpg123,关于 mpg123 获取音频文件比特率的问题

啊啦 作为小白 实在扛不住了 还是决定到论坛上来咨询一下了 涉及 gem&#xff1a;audite , mpg123 , portaudio 事件描述&#xff1a; 我最近在练习 ruby &#xff0c;决定把虾米猜电台写个 ruby 版。我想把 下载进度 和 播放进度 以进度条的形式展现出来&#xff0c;所以我至少…