android - 如何获取字符串日期中的周数
问题描述
如果我有一个字符串日期,如“04/06/2019 5:11:37 PM”、“09/03/”,如何获取一个月中的周数和一个月中某个日期的周数2019 年 10 点 47 分 43 秒”、“2019 年 1 月 1 日上午 1 点 36 分 39 秒”。
例如,2019 年 9 月 3 日。三月的周数是:x 09 三月是周数:x
解决方案
首先包括您的输入格式
String input = "2019/03/09";
String format = "yyyyMMdd";
SimpleDateFormat df = new SimpleDateFormat(format);
Date date = df.parse(input);
// you can parse it as Calendar object
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int week = cal.get(Calendar.WEEK_OF_YEAR);
推荐阅读
- python - AnalysisException:在根据前几行计算列值时,窗口函数中不支持表达式
- php - 从 php codeigniter 发送的电子邮件无法在特定域上接收
- android - 如何在没有网站的情况下设置包名称?
- android - 以编程方式将 Fragment 添加到 Kotlin 中的 Activity
- java - 无法在全新的 Manjaro 安装上启动 Eclipse (2019-12)
- hyperledger-fabric - Hyperledger 结构对等更新失败:签名集不满足策略
- javascript - 我的代码如何理解该函数和超时正在运行?
- string - Dart 中等效的 strstr 函数
- reactjs - 第一次渲染我的元素时,参考电流始终为空?
- git - 将弹性 beanstalk 配置复制到另一个区域的环境中