• DateTimeFormatter


    <div class="show-content-free">
            <pre><code class="java hljs"><ol class="hljs-ln"><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="1"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-comment">//解析日期</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="2"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">String dateStr= <span class="hljs-string">"2018年12月18日"</span>;</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="3"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">DateTimeFormatter formatter = DateTimeFormatter.ofPattern(<span class="hljs-string">"yyyy年MM月dd日"</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="4"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">LocalDate date= LocalDate.parse(dateStr, formatter);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="5"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"> </div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="6"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line"><span class="hljs-comment">//日期转换为字符串</span></div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="7"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">LocalDateTime now = LocalDateTime.now();</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="8"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">DateTimeFormatter format = DateTimeFormatter.ofPattern(<span class="hljs-string">"yyyy年MM月dd日 hh:mm a"</span>);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="9"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">String nowStr = now .format(format);</div></div></li><li><div class="hljs-ln-numbers"><div class="hljs-ln-line hljs-ln-n" data-line-number="10"></div></div><div class="hljs-ln-code"><div class="hljs-ln-line">System.out.println(nowStr);</div></div></li></ol></code><div class="hljs-button signin" data-title="登录后复制" onclick="hljs.signin(event)"></div></pre>
    
          </div>
                                      </div>
  • 相关阅读:
    R语言导入scv文件乱码问题及解决
    水论文而已,科研就交给恐龙吧
    R语言实现单因素方差分析带字母的显著性标记
    记录新的学习
    如果你的校园网连不上很有可能是因为IE代理服务出错导致无法上网
    git 补充
    git
    学习linux的菜鸟 shell脚本中的循环
    学习linux的菜鸟 shell脚本中的逻辑判断
    学习linux的菜鸟 shell脚本中的dat,计算器,内置变量的用法
  • 原文地址:https://www.cnblogs.com/jpfss/p/11245341.html
Copyright © 2020-2023  润新知