6

I'm working up a custom Xcode template, and I'd like to change the way <<date>> is formatted.

For example:

//  Created by «FULLUSERNAME» on «DATE».
//  Copyright «YEAR» «ORGANIZATIONNAME». All rights reserved.

if the file was created today would fill as:

//  Created by SooDesuNe on 2/24/2010.
//  Copyright 2010 MyOrganization. All rights reserved.

Dates formatted in any "all numbers" format can cause a lot of confusion, since the ISO and JIS way of writing the same date is 24/2/2010. It's clear on the 24th day of the month, but not so clear on the first 12 days of the month.

I would like x-code to populate <<date>> like:

//  Created by SooDesuNe on 24-Feb-2010.
//  Copyright 2010 MyOrganization. All rights reserved.

Since there is no ambiguity that way. Anyone know how to change the date format?

Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
SooDesuNe
  • 9,880
  • 10
  • 57
  • 91

3 Answers3

12
defaults write com.apple.dt.xcode AppleICUDateFormatStrings '{ 1 = "d-MMM-y"; }'
Nicholas Riley
  • 43,532
  • 6
  • 101
  • 124
  • Copied that into the terminal, and created a new file from my template. But the date formate was still mm/dd/yy – SooDesuNe Feb 26 '10 at 03:07
  • That got it, thanks! Where is that type of information documented? – SooDesuNe Feb 27 '10 at 01:39
  • It isn't. The date formats are from ICU, which OS X has used for a while; I just configured the format for myself in Date & Time System Preferences then did a 'defaults read -g' to see where it was written. Global defaults with a particular key are shadowed by the corresponding application defaults, which allows this to work. – Nicholas Riley Feb 27 '10 at 04:20
  • Not working on Xcode 9, even after a full system restart – Gobe Jan 30 '18 at 17:33
  • 1
    Xcode's bundle identifier has changed, so `com.apple.xcode` won't work any more; use `com.apple.dt.Xcode`. In general there is a new much more flexible system for file templates in Xcode 9; see for more information: https://oleb.net/blog/2017/07/xcode-9-text-macros/ (unfortunately all you get is a date or year though; you can't specify a date format inline from what I am aware). Also note that custom date formats have migrated into Language & Region Preferences under the Advanced… button. – Nicholas Riley Feb 03 '18 at 16:52
7

You can just change your short format of your time displaying in system preferences., then restart xcode, the default date format will be changed

sprhawk
  • 221
  • 3
  • 3
  • From my observation it looks like Xcode's settings in `~/Library/Preferences/com.apple.Xcode.plist` are overridden by system's time and date settings, so your solution worked for me after restarting Xcode. – matm Sep 01 '11 at 09:59
1

If you want to show the default Date and User name you can add these two lines in your ___FILEBASENAME___.swift file

// ___FILEBASENAMEASIDENTIFIER___
// Created by ___FULLUSERNAME___ on ___DATE___.

This will show the File name and created by the User and Current date.

However if you want to add the header you can add the below line

//___FILEHEADER___

Result will be:-

//
//  TestViewController.swift
//  MyProjectName
//
//  Created by Rashid on 28/12/2021.
// 
Rashid Latif
  • 2,809
  • 22
  • 26