package net.demo.test.date;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
public class Callout {
private static String CALLOUT_START_TIME = "08:00";
private static String CALLOUT_END_TIME = "20:00";
private static Callout instance = new Callout();
private boolean inited = false;
private Callout() {
if (!inited) {
init();
inited = true;
}
}
public static Callout getInstance() {
return instance;
}
public static void init() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd {0}:00");
sdf.setLenient(false);
Date date = new Date(System.currentTimeMillis());
String timeTemplate = sdf.format(date);
String defaultPeriod = "08:00-20:00";
// String CalloutPeriod =
// SystemConfigCache.getConfigValue("ivr_can_Callout_period",
// defaultPeriod);
String[] periods = defaultPeriod.split("-");
try {
Callout.CALLOUT_START_TIME = periods[0];
Callout.CALLOUT_END_TIME = periods[1];
} catch (Exception e) {
Callout.CALLOUT_START_TIME = "08:00";
Callout.CALLOUT_END_TIME = "20:00";
return;
}
String startTime = MessageFormat.format(timeTemplate,
Callout.CALLOUT_START_TIME);
String endTime = MessageFormat.format(timeTemplate,
Callout.CALLOUT_END_TIME);
SimpleDateFormat sdd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdd.setLenient(false);
try {
long start = sdd.parse(startTime).getTime();
long end = sdd.parse(endTime).getTime();
if (start > end) {
throw new ParseException("start time after end time", -1);
}
} catch (ParseException e) {
Callout.CALLOUT_START_TIME = "08:00";
Callout.CALLOUT_END_TIME = "20:00";
}
}
public static Date getCurrentTime() {
Date date = new Date(System.currentTimeMillis());
return date;
}
public static Date getStartTime() {
return getDate(Callout.CALLOUT_START_TIME);
}
public static Date getEndTime() {
return getDate(Callout.CALLOUT_END_TIME);
}
public static Date getDate(String time) {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd {0}:000");
String template = sdf.format(date);
String result = MessageFormat.format(template, time);
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setLenient(false);
try {
date = sdf.parse(result);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
public static void main(String[] args) {
boolean flag = canCallout();
System.out.println(flag);
//
flag = example();
System.out.println(flag);
}
public static boolean canCallout() {
long start = getStartTime().getTime();
long end = getEndTime().getTime();
long current = getCurrentTime().getTime();
if (start <= current && end > current) {
return true;
}
return false;
}
public void test() {
GregorianCalendar c = new GregorianCalendar(Locale.getDefault());
c.setLenient(false);
c.setTime(new Date());
}
/**
* Example
*/
public static boolean example() {
String DEFAULT_PERIOD = "08:00-20:00";
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
String currentTime = sdf.format(date);
// getSystemConfig();
String[] interval = DEFAULT_PERIOD.split("-");
if (currentTime.compareTo(interval[0]) > 0
&& currentTime.compareTo(interval[1]) < 0) {
return true;
}
return false;
}
}
分享到:
相关推荐
前端项目-messageformat,multipleformat和selectformat message和i18n工具-一个实现ICU标准的javascript。
此monorepo由构成我们的ICU MessageFormat的JS实现的以下程序包组成: core-将MessageFormat字符串转换为JavaScript函数的核心库库的命令行客户端将其他本地化格式转换为MessageFormat 用于工具 loader-用于JSON,...
messageformat.net, .NET的ICU MessageFormat实现 用于. NET 的- 更好的用户界面字符串。 这是. NET 中ICU消息格式的实现。 有关该格式的官方信息,请转到: http://userguide.icu-project.org/formatparse/messages...
官方版本,亲测可用
主要介绍了Java中的MessageFormat.format用法实例,本文先是讲解了MessageFormat的语法,然后给出了多个操作实例,需要的朋友可以参考下
messageformat.js 的代码镜像模式 此存储库提供用于编辑 MessageFormat 模板字符串的代码镜像模式。 语法高亮代码折叠和 linter 与编辑器集成。 如果您想看到它的实际效果,请尝试。 虽然有很多不同的 ...
消息格式包使用 messageformat.js 编译消息树。 输出中没有全局变量。安装 > npm install messageformat-bundle用法 var messageformatBundle = require ( 'messageformat-bundle' ) ;// Work in progress…应用程序...
ngx-translate-messageformat-compiler ngx-translate编译器,它使用messageformat.js来使用ICU语法编译翻译以处理复数形式和性别 (StackBlitz) 目录 安装 假设您已经安装了 。 使用npm : npm install ngx-...
利用MessageFormat格式化字符串实例资料.pdf
前端项目-angular-translate-interpolation-messageformat,使用messageformat.js根据某些值插入字符串。
前端项目-intl-messageformat,将ICU消息字符串格式化为数字、日期、复数,然后选择占位符以创建本地化消息。
主要介绍了Java利用MessageFormat实现短信模板的匹配,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Intl Messageformat Parser 是发送给 AST 的解析消息字符串,它可以格式化一个人的语言环境消息。
requirejs-messageformat RequireJS 插件来消费 MessageFormat 资源包 依赖关系 这个插件依赖于 Alex Sexton 的库以及文本! 插入。 MessageFormat 库必须位于您的源代码树中的路径下,您将使用该路径作为别名,如...
gettext-to-messageformat 使用将gettext输入(po / pot / mo文件)转换为兼容的JSON。 安装 npm install --save gettext-to-messageformat 或者 yarn add gettext-to-messageformat 如果在本机不支持ES6功能...
MessageFormat 编译对象编译 messageformat.js 翻译字符串对象。安装 npm install messageformat-compile-object --save用法 var compile = require('messageformat-compile-object');var obj = {locale: 'es'};obj....
适用于Webpack的YAML i18n加载程序...安装npm install messageformat-yaml-loader 或者yarn add messageformat-yaml-loader用法有关以下内容的有效演示, npm install在目录中运行npm install ,然后在浏览器中打开e
支持MessageFormat i18n,采用流星方式。 轻松React性地使用复杂的字符串(性别,复数形式),并且非常容易地将其翻译成其他语言(通过Web UI)。 特征 通过行业黄金标准MessageFormat使用超强大的语言 通过自动...
命令行界面CLI messageformat (可通过 npm 脚本使用)将 json 中的消息散列作为输入并生成一个 js 文件,该文件将编译的消息工厂导出为 UMD 模块。 和助手 CLI 工具(可通过 npm 脚本使用),基于 CLDR 数据: 复数...