arrays


How to add a date and time prefix to an array on Swift


The code listed below puts the text prefix car before each int array entry.
date | 2017-05-07 16:58:07 +0000:2,
var arrayOfInt = [Int]()
let cars = arrayOfInt.map { "car \($0)" }
label.text = String(describing: cars)
All I want to do is replace car with the date and time for each array entry when printed out.
Just append the date value in every iteration. For the time of creation just use create a new instance of Date.
To format the output of the date, use the DateFormatter. It allows you display the current time any way you like it.
var arrayOfInt = [1, 2, 3, 4]
let cars = arrayOfInt.map {
"date | \(Date.formattedNow()) \($0), "
}
print(String(describing: cars))
extension Date {
// Declare a static variable on `Date`, where you can modify your date output
static func formattedNow() -> String {
let now = Date()
let dateFormatter = DateFormatter()
// You need to update this property of the formatter, if you would like a different format
// For formats, see: http://nsdateformatter.com/
dateFormatter.dateFormat = "yyyy MMM EEEE HH:mm:ss"
dateFormatter.timeZone = TimeZone(identifier: "UTC")
return dateFormatter.string(from: now)
}

Related Links

ruby even Fibonacci numbers
Find common and unique items between two arrays
Powershell, Start-Job is not Working. Without Start-job script is Ok
Correctness of algorithm to find maximum in array
Using smart pointers for array
Why another array is replaced in julia?
Cannot plot a 2D array using contourf()
Efficient way of doing numerical integration on a 2d array with variable integration length
Reshape in Fortran90
Using any array
How to pass array to nsuserdefaults and use them in a section in tableview
Extract value from const array in Z3
How do you use the buffer? [intel based assembly]
Is there a built-in function in MATLAB to get bsxfun(#rdivide,abs(X),sum(abs(X)))?
Array does not work on Powershell 2.0
Iterate through array of hashes in ANT script

Categories

HOME
cluster-computing
filterrific
itext
rotation
blockchain
ipython
facebook-graph-api
angular2-routing
deep-linking
matplotlib
docker-windows
websphere-liberty
outlook-web-addins
uiscrollview
viber
jogl
primes
go-cd
azure-servicebus-queues
http-method
tampermonkey
maximo
image-quality
datadog
hibernate-cache
ipfw
google-guava-cache
magiczoomplus
ntfs-mft
pdftk
context-free-language
applepayjs
pdflib
typhoon
hspec
json-schema-validator
amf
ng2-material
cmocka
difference
selendroid
matcaffe
vine
prezto
manjaro
harp
apache-mina
ctrlp
x-ua-compatible
suffix-array
csplit
yahoo-boss-api
dvcs
sanitization
cling
java.util.date
bigint
loop-invariant
dig
html-form-post
ienumerator
dwolla
fraud-prevention
tridion2009
osi
cadisplaylink
xmlslurper
server-error
front-controller
callgrind
castle-validators
interface-design
dotproject

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App