我目前正在将excel文件另存为"Fin_report.xlsx"
,但我也希望将其保存日期纳入其中。它应该类似于:"Fin_report-yyyy-mm.xlsx"
其中yyyy-mm
是上个月的日期。例如,如果今天是2018-03-01,则今天的文件应保存为:"Fin_report-2018-02.xlsx"
答案 0 :(得分:1)
您正在寻找的是改变日期月份并将字符串插入另一个月份的混合物。
我会这样做,使用 <nav class="navbar navbar-inverse" style="background-color: #320143; margin-bottom:0px;">
<div class="container-fluid" id = "navbarcontainer" style = "margin-right:12%;">
<button class = "navbar-toggle" data-toggle = "collapse" data-target = ".navHeaderCollapse" style="border-color: #320143;">
<span class= "icon-bar"></span>
<span class= "icon-bar"></span>
<span class= "icon-bar"></span>
</button>
<div class = "collapse navbar-collapse navHeaderCollapse" style="height:100vh;">
<div class = "col-sm-5" style = "text-align: left;">
<ul class="nav navbar-nav navbar-left">
<li style="top: 9px;">
<div class="dropdown">
<button class="dropbtn" id="collapsed"><font face = "Tinos" size = "4"><b>Articles</b></font><span class="caret"></span></button>
<div class="dropdown-content">
<a href="http://www.heights-ateneo.org/news.php" id="collapsed"><font face = "Tinos" size = "4"><b>News</b></font></a>
<a href="http://www.heights-ateneo.org/features.php" id="collapsed"><font face = "Tinos" size = "4"><b>Features</b></font></a>
</div>
</div>
</li><li style="top: 12px;"><a href="http://www.heights-ateneo.org/folios.php" ><font face = "Tinos" size = "4"><b>Folios</b></font></a></li>
<li style="top: 12px;"><a href="http://www.heights-ateneo.org/CFC.php" ><font face = "Tinos" size = "4"><b>Contribute</b></font></a></li>
</ul>
</div>
<div class = "col-sm-1" style = "text-align: center;">
<div class="navbar-header">
<a href="<?php echo home_url(); ?>" id="collapsed"> <div class="navbar-brand button-icon hlogo"></div></a>
<div><span></span></div>
</div>
</div>
<div class = "col-sm-6" style = "text-align: left;">
<ul class="nav navbar-nav navbar-right" style = "margin-right: -20px;">
<li style ="top:9px;">
<div class="dropdown">
<button class="dropbtn" id = "abtbtn"><font face = "Tinos" size = "4"><b>About</b></font><span class="caret"></span></button>
<div class="dropdown-content">
<a href="http://www.heights-ateneo.org/about.php/" id="collapsed"><font face = "Tinos" size = "4"><b>About Us</b></font></a>
<a href="http://www.heights-ateneo.org/about.php/#history" id="collapsed"><font face = "Tinos" size = "4"><b>History</b></font></a>
<a href="http://www.heights-ateneo.org/about.php/#projects" id="collapsed"><font face = "Tinos" size = "4"><b>Projects</b></font></a>
</div>
</div>
</li>
<li style="top: 12px;"><a href="http://www.heights-ateneo.org/contact.php" ><font face = "Tinos" size = "4"><b>Contact</b></font></a></li>
<li style="top: 22px; margin-left:12px; margin-right:20px;"><div class="search-box"><div class="search-container">
<!-- <span class="icon"><i class="fa fa-search"></i></span> -->
<form action="http://heights-ateneo.org/" method="get" class="form-inline"><font face = "Tinos" size = "3"><input type="text" id="search" placeholder="Search..." name="s"/></font>
</div></div></li>
</ul>
</div>
</div>
</div>
</div>
</nav>
库来表示日期,并编写我自己的函数lubridate
,打印出上个月的月份。
last_month()
答案 1 :(得分:0)
仅使用基数R,您可以使用Sys.Date()
获取计算机上的当前时间。你可以减少&#39;使用seq()
的酷炫功能一个月,这将给你:
lastmonth <- seq(Sys.Date(), length=2, by="-1 months")[2]
# [1] "2018-02-01"
您只能使用format
format(lastmonth, "%Y-%m")
# [1] "2018-02"
然后您可以使用paste0
将字符串格式化为文件名:
filename <- paste0("Fin_report-", format(lastmonth, "%Y-%m"), ".xlsx")
filename
# [1] "Fin_report-2018-02.xlsx"