免费文章,只希望能帮助大家。收费不是我的初衷。

我想写过Java,C#,js....等都需要对时间进行各种操作。

1.戳进行格式化成自己想要的。例如[2019年08月01日,2019-08-01,2019?08?️01?
        11:24?️33⏲️,2019:08:01 11-12:22........]

2.将时间日期格式转化为时间戳,知道日期例如2019年08月01日,2019-08-01,2018年12月11日,2018年11月15 11:14分89
 获取结果是时间戳 
3.获取两个时间段内的所有时间段落,我想获取2018-01-20 到 2019-11-23之间的所有日
       期。例如:[2018年01月20日,2018年01月21日,2018年01月22日,2018年01月23日......2019
        年11月22日,2019年11月23日]
4.获取从那一天起到之后10,20,30.....天内的所有的时间日期.....
5.获取某一个月(或者时间戳)的最后一天日期。例如获取2019-02-05最后一天日期
       结果为:2019年02月28日

库地址flutter库地址

1.依赖

dependencies:

luhenchang_plugin: ^0.0.1

2.使用

二. 时间工具类的使用DateUtils.instance.getMilliseconds(formartDate:"2019-02-11 11月12日01")1.将时间格式转日期化为时间戳///formartDate=2018年12月11日    或者    2019-12-11   或者    2018年11月15 11:14分89///结果是毫秒int getMilliseconds({String formartDate = "1970-10-01 00:00:00"})2.格式化时间戳 ///timeSamp:毫秒值 ///format:"yyyy年MM月dd hh:mm:ss" "yyy?MM?dd hh?MM?dd" "yyyy:MM:dd"...... ///结果: 2019?08?04 02?08?02 String getFormartDate(inttimeSamp,{format="yyyy年MM月dd hh:mm:ss"})3.获取从某一天开始到某一天结束的所有的中间日期,例如输入 startTime:2019:07:31  endTime:2019:08:31  就会返回所有的中间天数。///startTime和endTime格式如下都可以///使用:List<String> mDate=DateUtils.instance.getTimeBettwenStartTimeAndEnd(startTime:"2019-07-11",endTime:"2019-08-29",format:"yyyy年MM月dd");///结果:[2019年07月11, 2019年07月12, 2019年07月13, 2019年07月14, 2019年07月15, 2019年07月16, 2019年07月17, 2019年07月18, 2019年07月19, 2019年07月20, 2019年07月21, 2019年07月22, 2019年07月23, 2019年07月24, 2019年07月25, 2019年07月26, 2019年07月27, 2019年07月28, 2019年07月29, 2019年07月30, 2019年07月31, 2019年08月01, 2019年08月02, 2019年08月03, 2019年08月04, 2019年08月05, 2019年08月06, 2019年08月07, 2019年08月08, 2019年08月09, 2019年08月10, 2019年08月11, 2019年08月12, 2019年08月13, 2019年08月14, 2019年08月15, 2019年08月16, 2019年08月17, 2019年08月18, 2019年08月19, 2019年08月20, 2019年08月21, 2019年08月22, 2019年08月23, 2019年08月24, 2019年08月25, 2019年08月26, 2019年08月27, 2019年08月28, 2019年08月29]List<String> getTimeBettwenStartTimeAndEnd({startTime: String, endTime: String, format: String}) 4.获取从某一天开始和之后的多少天内的所有你需要格式化样式的时间日期。///tarTime: 开始日期 2012-02-27 13:27:00 或者 "2012-02-27等....///dayNumber:从startTime往后面多少天你需要输出///formart:获取到的日期格式。"yyyy年MM月dd" "yyyy-MM-dd" "yyyy年" "yyyy年MM月" "yyyy年\nMM月dd"  等等///使用:DateUtils.instance.getTimeStartTimeAndEnd(startTime:"2019-07-11",dayNumber:10,format:"yyyy年MM月dd");///结果:[2019年07月11, 2019年07月12, 2019年07月13, 2019年07月14, 2019年07月15, 2019年07月16, 2019年07月17, 2019年07月18, 2019年07月19, 2019年07月20, 2019年07月21]List<String> getTimeStartTimeAndEnd({String startTime="1970-01-01",int dayNumber:1,String format="yyyy年MM月dd"})5.获取从某一天时间戳开始和之后的多少天内的所有你需要格式化样式的时间日期。///startTime:输入其实时间的时间戳也可以。例如 1570723200000///dayNumber:所需要后面的几天以内的日期数字 1///format 输入时间格式List<TimeDate> getTimeStartTimeAndEndTime6.获取某一个月的最后一天。///我们能提供和知道的条件有:(当天的时间,)///timeSamp:时间戳 单位(毫秒)///format:想要的格式  "yyyy年MM月dd hh:mm:ss"  "yyy?MM?dd  hh?MM?dd" "yyyy:MM:dd"getEndMoth(int timeSamp, {format="yyyy年MM月dd hh:mm:ss"}) 7.获取某一个月的最后一天。///我们能提供和知道的条件有:(当天的时间,)///timeSamp:时间戳 单位(毫秒)///format:想要的格式  "yyyy年MM月dd hh:mm:ss"  "yyy?MM?dd  hh?MM?dd" "yyyy:MM:dd"getEndMothFor({mothFormartTime="1970年01月01", format: String}) 
/** 关于时间工具* @作者路很长* @路很长的博客地址 https://blog.csdn.net/m0_37667770/article/details/80903890* @路很长github  https://github.com/luhenchang/flutter_study*/
class DateUtils {// 工厂模式factory DateUtils() => _getInstance();static DateUtils get instance => _getInstance();static DateUtils _instance;DateUtils._internal() {// 初始化}static DateUtils _getInstance() {if (_instance == null) {_instance = new DateUtils._internal();}return _instance;}///将时间日期格式转化为时间戳///formartDate=2018年12月11日    或者    2019-12-11   或者    2018年11月15 11:14分89///结果是毫秒int getMilliseconds({String formartDate = "1970-10-01 00:00:00"}) {//年必须大于1970年String mYear = formartDate.substring(0, 4);if (int.parse(mYear) < 1970) {mYear = "1970";}var result;try {result = mYear +"-" +formartDate.substring(5, 7) +"-" +formartDate.substring(8, 10);if (formartDate.toString().length >= 13 &&formartDate.substring(10, 13) != null) {result += "" + formartDate.substring(10, 13);}if (formartDate.toString().length >= 17 &&formartDate.toString().substring(14, 16) != null) {result += ":" + formartDate.substring(14, 16);}if (formartDate.toString().length >= 19 &&formartDate.substring(17, 19) != null) {result += ":" + formartDate.substring(17, 19);}print(result);var dateTime = DateTime.parse(result);return dateTime.millisecondsSinceEpoch;} catch (e) {throw e;}}///格式化时间戳///timeSamp:毫秒值///format:"yyyy年MM月dd hh:mm:ss"  "yyy?MM?dd  hh?MM?dd" "yyyy:MM:dd"......///结果: 2019?08?04  02?08?02String getFormartDate(int timeSamp,{format="yyyy年MM月dd hh:mm:ss"}){var DateFormart = new DateFormat(format);var dateTime = new DateTime.fromMillisecondsSinceEpoch(timeSamp);String formartResult = DateFormart.format(dateTime);return formartResult;}///1.获取从某一天开始到某一天结束的所有的中间日期,例如输入 startTime:2019:07:31  endTime:2019:08:31  就会返回所有的中间天数。///startTime和endTime格式如下都可以///使用:    List<String> mDate=DateUtils.instance.getTimeBettwenStartTimeAndEnd(startTime:"2019-07-11",endTime:"2019-08-29",format:"yyyy年MM月dd");///结果:[2019年07月11, 2019年07月12, 2019年07月13, 2019年07月14, 2019年07月15, 2019年07月16, 2019年07月17, 2019年07月18, 2019年07月19, 2019年07月20, 2019年07月21, 2019年07月22, 2019年07月23, 2019年07月24, 2019年07月25, 2019年07月26, 2019年07月27, 2019年07月28, 2019年07月29, 2019年07月30, 2019年07月31, 2019年08月01, 2019年08月02, 2019年08月03, 2019年08月04, 2019年08月05, 2019年08月06, 2019年08月07, 2019年08月08, 2019年08月09, 2019年08月10, 2019年08月11, 2019年08月12, 2019年08月13, 2019年08月14, 2019年08月15, 2019年08月16, 2019年08月17, 2019年08月18, 2019年08月19, 2019年08月20, 2019年08月21, 2019年08月22, 2019年08月23, 2019年08月24, 2019年08月25, 2019年08月26, 2019年08月27, 2019年08月28, 2019年08月29]List<String> getTimeBettwenStartTimeAndEnd({startTime: String, endTime: String, format: String}) {var mDateList = List<String>();//记录往后每一天的时间搓,用来和最后一天到做对比。这样就能知道什么时候停止了。int allTimeEnd = 0;//记录当前到个数(相当于天数)int currentFlag = 0;DateTime startDate = DateTime.parse(startTime);DateTime endDate = DateTime.parse(endTime);var mothFormatFlag = new DateFormat(format);while (endDate.millisecondsSinceEpoch > allTimeEnd) {allTimeEnd =startDate.millisecondsSinceEpoch + currentFlag * 24 * 60 * 60 * 1000;var dateTime = new DateTime.fromMillisecondsSinceEpoch(startDate.millisecondsSinceEpoch + currentFlag * 24 * 60 * 60 * 1000);String nowMoth = mothFormatFlag.format(dateTime);mDateList.add(nowMoth);currentFlag++;}return mDateList;}///获取从某一天开始和之后的多少天内的所有你需要格式化样式的时间日期。///tarTime: 开始日期 2012-02-27 13:27:00 或者 "2012-02-27等....///dayNumber:从startTime往后面多少天你需要输出///formart:获取到的日期格式。"yyyy年MM月dd" "yyyy-MM-dd" "yyyy年" "yyyy年MM月" "yyyy年\nMM月dd"  等等///使用:DateUtils.instance.getTimeStartTimeAndEnd(startTime:"2019-07-11",dayNumber:10,format:"yyyy年MM月dd");///结果:[2019年07月11, 2019年07月12, 2019年07月13, 2019年07月14, 2019年07月15, 2019年07月16, 2019年07月17, 2019年07月18, 2019年07月19, 2019年07月20, 2019年07月21]List<String> getTimeStartTimeAndEnd({String startTime="1970-01-01",int dayNumber:1,String format="yyyy年MM月dd"}) {var mDateList = List<String>();//记录往后每一天的时间搓,用来和最后一天到做对比。这样就能知道什么时候停止了。//记录当前到个数(相当于天数)int currentFlag =0;DateTime startDate = DateTime.parse(startTime);var mothFormatFlag = new DateFormat(format);print(startDate.millisecondsSinceEpoch);while (dayNumber >= currentFlag) {var dateTime = new DateTime.fromMillisecondsSinceEpoch(startDate.millisecondsSinceEpoch + currentFlag * 24 * 60 * 60 * 1000);String nowMoth = mothFormatFlag.format(dateTime);mDateList.add(nowMoth);currentFlag++;}return mDateList;}///获取从某一天时间戳开始和之后的多少天内的所有你需要格式化样式的时间日期。///startTime:输入其实时间的时间戳也可以。例如 1570723200000///dayNumber:所需要后面的几天以内的日期数字 1///format 输入时间格式List<TimeDate> getTimeStartTimeAndEndTime({startTime: int, dayNumber: int, format: String}) {var mDateList = List<TimeDate>();//记录往后每一天的时间搓,用来和最后一天到做对比。这样就能知道什么时候停止了。int allTimeEnd = 0;//记录当前到个数(相当于天数)int currentFlag = 0;var mothFormatFlag = new DateFormat(format);while (dayNumber >= currentFlag) {TimeDate timeDate = new TimeDate();var dateTime = new DateTime.fromMillisecondsSinceEpoch(startTime + currentFlag * 24 * 60 * 60 * 1000);String nowMoth = mothFormatFlag.format(dateTime);timeDate.DateTime = nowMoth;timeDate.week = dateTime.weekday;mDateList.add(timeDate);currentFlag++;}return mDateList;}///获取某一个月的最后一天。///我们能提供和知道的条件有:(当天的时间,)///timeSamp:时间戳 单位(毫秒)///format:想要的格式  "yyyy年MM月dd hh:mm:ss"  "yyy?MM?dd  hh?MM?dd" "yyyy:MM:dd"getEndMoth(int timeSamp, {format="yyyy年MM月dd hh:mm:ss"}) {var dateFormart = new DateFormat(format);var dateTime = new DateTime.fromMillisecondsSinceEpoch(timeSamp);var DateNextMonthDate = new DateTime(dateTime.year, dateTime.month + 1, 1);int nextTimeSamp =DateNextMonthDate.millisecondsSinceEpoch - 24 * 60 * 60 * 1000;//取得了下一个月1号码时间戳var dateTimeeee = new DateTime.fromMillisecondsSinceEpoch(nextTimeSamp);String formartResult = dateFormart.format(dateTimeeee);return formartResult;}///获取某一个月的最后一天。///我们能提供和知道的条件有:(当天的时间,)///timeSamp:时间戳 单位(毫秒)///format:想要的格式  "yyyy年MM月dd hh:mm:ss"  "yyy?MM?dd  hh?MM?dd" "yyyy:MM:dd"getEndMothFor({mothFormartTime="1970年01月01", format: String}) {DateTime startDate = DateTime.parse(mothFormartTime);var dateFormart = new DateFormat(format);//DateTime获取年和月var dateTime = new DateTime.fromMillisecondsSinceEpoch(startDate.millisecondsSinceEpoch);//通过DateTime获取当月的下个月第一天。var DateNextMonthDate = new DateTime(dateTime.year, dateTime.month + 1, 1);//下一个月的第一天时间戳减去一天的时间戳就是当前月的最后一天的时间戳int nextTimeSamp =DateNextMonthDate.millisecondsSinceEpoch - 24 * 60 * 60 * 1000;//取得了下一个月1号码时间戳var dateTimeeee = new DateTime.fromMillisecondsSinceEpoch(nextTimeSamp);String formartResult = dateFormart.format(dateTimeeee);return formartResult;}
}class TimeDate {String DateTime;int week;
}

Flutter时间日期格式化等操作(一个月的最后一天日期,时间段内所有日期...)相关推荐

  1. 一年中最后一个月的最后一天说说_一年最后一天怎么发朋友圈

    睁开眼睛,看见阳光洒满房间,温暖心房.忘掉昨日不快,迎接今日豪迈.用热情开始一天新的生活!今天是2020的最后一天,你有什么心情感悟呢?下面是小编为大家整理的关于一年最后一天怎么发朋友圈,希望对您有所 ...

  2. 计算用户输入的日期离1900年1月1日相距多少天。日期要大于1900(注意闰年,每个月份天数不一样)

    import java.util.Scanner;public class test {public static void main(String[] args) {//计算用户输入的日期离1900 ...

  3. 简单快捷计算本月第一天星期几、本月有多少天、上一个月的最后一天是几号

    今天偶然在vue2/nodejs视频中看到一个计算"本月第一天星期几.本月有多少天.上一个月的最后一天是几号" 最简便最快捷的方法. 如果自己写,就很容易要判断闰年问题,那就非常复 ...

  4. python报表自动化系列 - 获取某个时间段内所有日期

    python获取某个时间段内所有日期并以列表返回 李俊才 邮箱:291148484@163.com [调用其它函数] 获取某年某月的天数:get_days(yearmonth) 博文地址:https: ...

  5. mysql查询时间段内所有日期 和 小时

    返回时间段内所有日期 天 select DATE_FORMAT(date_add('2022-06-01 00:00:00', interval row DAY),'%Y-%m-%d') date f ...

  6. 将日期设定成上一个月,上一年。

    Date date = new Date();//当前时间String data1 = "2022-01-01";//指定专门的时间String format = "yy ...

  7. java中使用Calendar日期类获得下一个月有多少天

    通过Calendar计算下一个月的年 月 以及下一月有多少天 //计算下一个月Calendar calendar=Calendar.getInstance();//获得当前日期往后推1个月 amoun ...

  8. oracler日期函数相差六个月_Oracle数据库之SQL单行函数---日期函数集锦

    前言 Oracle数据库的日期函数是十分强大的,而且也比较的多.笔者将之整理下来供日后的参考 使用.于自己便利,也于别人便利! 常用日期型函数 1.Sysdate: 当前的日期和时间select Sy ...

  9. 一年中最后一个月的最后一天说说_2019最后一个月的心情感言 2019最后一个月的朋友圈说说...

    2019年已经进入了倒计时,只剩下最后一个月,日历翻过了一页又一页,回顾2019年的过往,五味杂陈,那么,2019年最后一个月你有什么心情感言呢?下面八宝网小编就带来2019最后一个月的心情感言,20 ...

  10. 一年中最后一个月的最后一天说说_2020只剩最后一个月的励志说说致自己

    所有的努力,不是为了让别人觉得你了不起,而是为了能让自己打心眼里看得起自己.2021进入倒计时了,努力加油吧 1.面对困难.挫折.挑战只要你肯相信自己,不断努力的付出,哪怕你现在的人生是从零开始,你都 ...

最新文章

  1. etrace 跟踪程序函数动态执行流程
  2. Python Django 一对一多表设计数据保存
  3. Mycat 之 通过Keepalived 实现高可用
  4. java 运行管理-基础
  5. FF:纳斯达克要求退市系误读 警示函仅与推迟提交Q3财报相关
  6. 一个能让html标签变成文本的html标签lt;xmpgt;
  7. Now that half a year has passed
  8. Mac python入门:安装python并新建python项目
  9. 解决VS2019配置QT6.1.1出现大量错误信息
  10. 电力电子技术笔记-逆变电路
  11. MPlyaer播放高清视频的说明(CoreAVC、提高速度和清晰度等问题)
  12. 2022年信息安全工程师考试知识点:信息安全法律法规
  13. Verilog——三角波发生器(状态机)
  14. 市场供需简单模型分析
  15. GIT远程分支误删恢复
  16. Maya群体堆积特效插件RubbishDumper垃圾倾倒夫1.0.3下载及教程
  17. yudian温控表a1温度怎么补偿_yudian温控表a1说明书
  18. Java - Eclipse: quot;Error notifying a preference change listenerquot;
  19. wpsa4排版_WPS如何快速排版
  20. 方舟服务器建家位置,方舟生存进化新手建家图文攻略 方舟生存进化在哪建家比较好-游侠网...

热门文章

  1. 商务网站建设与维护【12】
  2. TYPE g_date_tbl_typ IS TABLE OF DATE INDEX BY VARCHAR2(1000);
  3. 什么是深拷贝与浅拷贝
  4. 阿里网盘资源查找使用技巧
  5. 计算机专业技能考核方案,计算机专业技能课教学考核方案
  6. 计算机管理十大突出问题,TPM设备管理十大问题
  7. 学习微服务最好的方式:阅读《微服务架构设计模式》
  8. 联想Y7000P win11笔记本双硬盘安装Ubuntu20双系统和显卡驱动
  9. 为什么要ROS2而不是对ROS1修修补补?
  10. oppo android多大内存,OPPO R9的内存容量是多少