zoukankan      html  css  js  c++  java
  • Orcale日期函数to_date(),to_char()

    日期转换的两个函数分别是to_date()和to_char(),to_date() 作用将字符类型按一定格式转化为日期类型, to_char() 将日期转按一定格式换成字符类型

    其中当时间需要精确的时候,最好使用to_char()使用字符类型进行比较,比较方法(=、>=、 <=、between   and )<、>需要转义,分别为&lt;  &gt;

     

    to_date:

        to_date('2018-01-20','yyyy-mm-dd'),前者为字符串,根据传入的格式模板将字符串日期为转为特定格式的date格式

       需要注意的是当转换的日期格式包含时分秒:to_date('2018-01-20 12:34:56', 'yyyy-mm-dd hh24:mi:ss'),模板有HH,HH12(按照12小时制,12小时格式下时间范围为: 0:00:00 - 23:59:59)   HH24:()按照24小时制,取值为0:00:00 - 23:59:59)

    to_char:

      to_char(dateType,'yyyy-mm-dd hh24:mi:ss')  将传入的格式为date的日期 dateType转成字符类型的年月日

      查询给定日期是周几:

         select to_char(to_date('2018-01-20','yyyy-mm-dd'),'day') from dual;   //星期六

    获取给定时间的七天前的日期:

     String createTime = "2018-01-20"
    Calendar before7day = Calendar.getInstance(); Date date = null;
    try { date = new SimpleDateFormat("yy-MM-dd").parse(createTime); before7day.setTime(date); int day = before7day.get(Calendar.DATE); before7day.set(Calendar.DATE, day - 7); String dayBefore = new SimpleDateFormat("yyyy-MM-dd").format(before7day.getTime());

    } catch (ParseException e) {
    e.printStackTrace();
    }

     

  • 相关阅读:
    webapp开发绝对定位引发的问题
    git下配置github sshkey
    html5 filereader读取流注意事项
    神奇的负Margin
    泪奔的ie
    第二次作业-实践一 网络攻防环境的搭建
    20199115 2019-2020-2 《网络攻防实践》第一周作业
    《网络攻防实践》寒假作业
    C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
    getline()函数
  • 原文地址:https://www.cnblogs.com/gczmn/p/8321175.html
Copyright © 2011-2022 走看看